0

I am putting a custom module together. It will take data submitted from a form from site users and store it in the DB. Admins will then be able to review the data and make changes to it. It is easy enough to display the DB data with something like:

return theme('item_list', array('header' => $header,'items' => $rows));

But I need to customize it to have custom HTML markup. Any thoughts, answers or direction?

closed as too broad by Kevin, Pierre.Vriens, Neograph734, kiamlaluno Sep 22 '17 at 4:14

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • You can literally enter anything as the theme function and its list of arguments provided by Drupal core, or, create your own via hook_theme and implement it. But this question is rather broad because its not clear on what you are actually trying to achieve beyond that. – Kevin Sep 21 '17 at 1:23
0

There are 2 ways of doing it. First one is to define your own theme function using hook_theme and then either create a theme function of a template file inside of your module or theme folder. example code is given here

/**
 * Implements hook_theme().
 */
function MYMODULE_theme($existing, $type, $theme, $path) {
  $custom_theme = array();
  $custom_theme['my_new_theme'] = array(
    // example theme template register
    // for 
    //sites/all/modules/mymodule/templates/my_new_theme.tpl.php
    'template' => 'my-new-theme',//dash will convert to underscore in template name.
    'path' => drupal_get_path('module', 'mymodule') . '/templates',
    'variables' => array('header' => null,'rows'=>null),
  );

  return $custom_theme;
}

You can then use

theme('my_new_theme', array('header' => $header, 'rows' => $rows));

instead of your theme function call. And then inside of your my_new_theme.tpl.php you can access $header and $rows variables.

Second method is not recommended but a possible way of doing this. So you can just create your HTML output in your callback function where you are creating that list. Store your full html to be out-puted in some variable and finally just return that variable at the end. Drupal will render your HTML as it is.

  • Still just sorting out how exactly it the system delivers content and uses templates in themes and modules. This helped! – Anthony R Sep 21 '17 at 15:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.