0

I have a custom module that generates a page of output, my question is about how to add html elements to the output such as headings and paragraphs etc.

My module is as follows

function mymodule_page() {
$output .= '<h3>'.t('Installs '.$cell).'</h3>';
$output .= theme('flot_graph', $graph1);
return $output;
}

is this the correct way to do this?

should line two be like this instead?

$output .= t('<h3>Installs '.$cell.'</h3>');
Daniel Harper
  • 496
  • 4
  • 19

1 Answers1

1

I prefer do not mix logic and presentation in module files, so I would use a tpl to print the content. For example, in your module I would put this code:

function mymodule_page() {
    return theme_render_template(drupal_get_path('theme', 'your_theme') . 'path/to/your/file.tpl', array('cell' => $cell, 'graph1' => $graph1); 
}

And in the tpl file:

<h3><?php echo t('Installs') . ' ' . $cell; ?></h3>
theme('flot_graph', $graph1);
m4t1t0
  • 5,669
  • 3
  • 22
  • 30
  • Would it be appropriate for me to create a directory in my module directory called theme and then just creare mymodule.tpl.php? – Daniel Harper Feb 11 '13 at 09:23
  • Yes, there is no problem for that, that way you do your modules independent from your themes and that is a good idea. – m4t1t0 Feb 11 '13 at 09:49
  • I actually had to pass the variables in an associative array like this array('cell' => $cell, 'graph' => $graph); – Daniel Harper Feb 11 '13 at 11:59