【问题标题】:Drupal html output themeDrupal html 输出主题
【发布时间】:2013-02-11 08:56:03
【问题描述】:

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

我的模块如下

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

这是正确的做法吗?

第二行应该改为这样吗?

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

【问题讨论】:

    标签: drupal drupal-7 drupal-modules drupal-themes


    【解决方案1】:

    我不喜欢在模块文件中混合逻辑和表示,所以我会使用 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);
    

    【讨论】:

    • 是否适合我在我的模块目录中创建一个名为主题的目录,然后创建 mymodule.tpl.php?
    • 是的,这没有问题,这样你就可以独立于你的主题来做你的模块,这是个好主意。
    • 我实际上必须在关联数组中传递变量,比如这个数组('cell' => $cell, 'graph' => $graph);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-08
    相关资源
    最近更新 更多