【问题标题】:Drupal 7 theme not called?没有调用 Drupal 7 主题?
【发布时间】:2017-09-12 14:14:42
【问题描述】:

我尝试在自定义模块中制作我的自定义表单的模板,但我无法调用 .tpl.php

这是我在我的主题 template.php 文件中的函数(位于:drupal/sites/all/themes/atheme):

 function atheme_theme() {
 return array(
  // Defines the form ID as a theme hook.
   'agendize_multistep_form' => array(
    // Specifies 'form' as a render element.
  'render element' => 'form',
    'path' => drupal_get_path('theme', 'atheme') . '/templates',
'template' => 'agendize_multistep_form',
),
  ); 
}

我的表单 id 是:agendize_multistep_form(我用 drupal_set_message 检查过)

我的模板文件位于:

drupal/sites/all/themes/atheme/templates/agenize_multistep_form.tpl.php

我故意放了一个空白的tpl,以便显示一个空白表格。 但我仍然有(即使清除了缓存)我的表单显示了所有元素,就像我从未声明过这个主题覆盖一样。

感谢您的帮助

【问题讨论】:

    标签: php drupal-7 theming


    【解决方案1】:

    希望下面的代码对你有帮助。

    atheme/template.php:

    function atheme_theme($existing, $type, $theme, $path) {
        $items['agendize_multistep_form'] = array(
            'render element' => 'form',
            'template' => 'agendize_multistep_form',
            'path' => drupal_get_path('theme', 'atheme') . '/template',
        );
    
        return $items;
    }
    

    agenize_multistep_form():

    function agendize_multistep_form($form, &$form_state) {
        $form['first_name'] = array(
            '#type' => 'textfield',
            '#attributes' => array('placeholder' => t('First name')),
        );
        $form['last_name'] = array(
            '#type' => 'textfield',
            '#attributes' => array('placeholder' => t('Last name')),
        );
        $form['submit'] = array(
            '#type' => 'submit',
            '#value' => 'Submit',
        );
        return $form;
    }
    

    atheme/template/agenize_multistep_form.tpl.php:

    <div class="agendize-form">
        <div class="firstname">
            <?php print render($form['first_name']); ?>
        </div>
        <div class="lastname">
            <?php print render($form['last_name']); ?>
        </div>
        <div class="submit">
            <?php print render($form['submit']); ?>
        </div>
    </div>
    
    <!-- Render any remaining elements, such as hidden inputs (token, form_id, etc). -->
    <?php print drupal_render_children($form); ?>
    

    请清除缓存并检查一下。

    【讨论】:

    • 您给出的唯一区别是关于主题方法中给出的参数。我把这个放好,还是一样,即使清除了缓存,也没有应用主题。事实上,如果我在 tpl.php 中什么都不放,我仍然会显示我的组件。由于 tpl 为空,它必须显示一个空白页
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多