0

我有一个生成输出页面的自定义模块,我的问题是如何将 html 元素添加到输出中,例如标题和段落等。

我的模块如下

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

这是正确的方法吗?

第二行应该是这样吗?

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

1 回答 1

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); 
}

在 tpl 文件中:

<h3><?php echo t('Installs') . ' ' . $cell; ?></h3>
theme('flot_graph', $graph1);
于 2013-02-11T09:12:58.577 回答