2013-02-11 108 views
0

我有一个生成输出的页面自定义模块,我的问题是关于如何将HTML元素添加到输出,如标题和段落等Drupal的HTML输出主题

我的模块有:

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

这是正确的方法吗?

应该是这样的行吗?

$output .= t('<h3>Installs '.$cell.'</h3>'); 

回答

0

我宁愿不要在模块文件中混合逻辑和表示,所以我会用tpl来打印内容。例如,你的模块中,我会把这个代码:

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

而在第三方物流文件:

<h3><?php echo t('Installs') . ' ' . $cell; ?></h3> 
theme('flot_graph', $graph1); 
+0

这将是适当的,我在我的模块目录创建一个名为主题,然后就creare mymodule.tpl.php? – 2013-02-11 09:23:26

+0

是的,这没有问题,那样你就可以使你的模块独立于你的主题,这是一个好主意。 – m4t1t0 2013-02-11 09:49:51

+0

我实际上不得不像这个数组一样在关联数组中传递变量('cell'=> $ cell,'graph'=> $ graph); – 2013-02-11 11:59:30