How to link menu item to a page in Drupal7, that can display database content? I am using a custom module in my Drupal7 to add data in a form and then inserting it into the database. The form has fields like &quot;Menu Name&quot;, &quot;Image&quot;, etc. I want to know :

How can i show this dynamic content in my site, by clicking on each of the menu items?
In other words, how to link dynamic content to the menu items? The name of the menu item will be equal to one of the fields (Menu Name) in the form in my custom module. Each of the menu item pages can have a different design &amp; layout (based on form data).

Do i need to hack my page.tpl.php?

Do i need to create as many .tpl pages as those of menu items for showing the dynamic content?
I just want to know What is the best way to achieve this.
There are 3 broad ways of doing this i) create a widget ii) ajax/json iii) create a block.

The widget method is suitable if you are trying to create an element in the form that is more sophisticated than the form elements provided. You present it in a node--contenttype.tpl.php template. Replace 'contenttype' with the name of the content type you created. 

If you want to print out just parts of the data captured in the form then you can use hide($content['fieldname') to get rid of any fields that you don't want rendered. That is the 'streamlined' way. See the 'field example' module in the examples project. 

Assuming the module is called ognotify you will need to implement: 


ognotify_field_info() to declare the field 
ognotify_field_widget_info to define the widget and
ognotify_field_formatter_info() to define the available formats. 


These 3 things define the 'edit content type form' in the administration area of drupal. 

To process the output you also need to implement 


ognotify_field_is_empty($item, $field)
ognotify_field_widget_form(&amp;$form, &amp;$form_state, $field, $instance,
$langcode, $items, $delta, $element) to define the form elements


and some validation routines. You can add this 'widget' to any content type.

It sounds as though you are trying to render something more specific. If by dynamic you mean via ajax then one way is to create an ajax block and callback response from the block (module is called bookreview this time).

Define the block as per:

function bookreview_block_display($delta, $args) {
...


This calls a form element of ajax type.

function _bookreview_publish_review_link($args) {
  $block = array();
  if (empty($args['nid']) || empty($args['status'])) {
    return $block;
  }

  $block['content'] = array(
    '#type' =&gt; 'link',
    '#title' =&gt; 'Publish review',
    '#href' =&gt; 'bookreview/publish/' . $args['nid'],
    '#prefix' =&gt; '&lt;div class="publish-review" id="ajax-link-div-' . $args['nid'] . '"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
    '#ajax' =&gt; array(
    'effect' =&gt; 'fade',
    ),
 );

 ...
  return $block;
}


Render this on a page. You can do this by mapping blocks, or in code in a template: 

$block = module_invoke('bookreview', 'block_display', 'bookreview_publish_review_link', $args);
print render($block['content']


The callback in this example is 'bookreview/publish'. This is the 'access content from a menu' solution. Implement the menu: 

function bookreview_menu() {
  $items = array();
  $items[BOOKREVIEW_MODULE_NAME . '/publish/%node'] = array(
    'title' =&gt; 'Publish a Book Review',
    'page callback' =&gt; 'bookreview_publish_review',
    'page arguments' =&gt; array(2),
    'access callback' =&gt; 'bookreview_access_callback_check',
    'access arguments' =&gt; array(array(BOOKREVIEW_ADMIN_PERMISSION_NAME)),
    'type' =&gt; MENU_CALLBACK,
    'file' =&gt; 'includes/BookReviewEvents.php',
  );
  return $items;
}


Now we have mapped a menu item (uri) to a function that prints out the content.

function bookreview_publish_review($node) {
  if (!isset($node)) {
    return;
  }


This takes a node argument, %node in the menu definition which automatically gets converted from a node number to a node loaded from the database. The address publish/123 will result in node 123 being passed to your function. You can create a callback for each of the fields in the content type as per /bookreview/menu-name-field/%node. Then create a function to either directly print out the ajax json response: 

...
// How you want to get the data from the node. Best to use Netbeans/php debugger
// or dpm() if you don't have it.
$menu_name_field_data = $this-&gt;node-&gt;{$this-&gt;_findMenuFieldName()}[LANGUAGE_NONE][$delta]['value'];
$data_to_print[] = $menu_name_field_data;
ajax_deliver(array('#type' =&gt; 'ajax', '#commands' =&gt; $data_to_print));
...


The 3rd way is similar to creating the ajax response, except that you define a block that allows you to render the html content. As per the ajax defining a menu item and declaring a block. You print out the content there instead of defining an ajax form. 

The widget answer is the most reusable, the ajax answer is the most dynamic and flexible and the block method presents HTML instead of ajax responses. Regarding 'dynamic' the ajax solution best meets your description in the question, although I thought it necessary to present the breadth of the possibilities so that you can make choices regarding the tradeoff between reuse and dynamic.