模块中的 Drupal 主题功能工作流程 [英] Drupal theme functions workflow in module

查看:21
本文介绍了模块中的 Drupal 主题功能工作流程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Drupal 主题的新手,我无法获得论坛模块主题的任何细节.

I am a bit newbie in Drupal theming and I can't get one detail in Forum modules theming.

forum.module 文件包含 forum_theme 函数,用于控制此模块的主题并有这条线

forum.module file contains forum_theme function that controls how this module is themed and has this line

function forum_theme() {
......
'forum_list' => array(
  'template' => 'forum-list',
  'arguments' => array('forums' => NULL, 'parents' => NULL, 'tid' => NULL),
),

我也在论坛目录中看到了forum-list.tpl.php文件,所以我开始想知道这个文件是什么时候被调用的,它从哪里获取数据,但我只能在论坛中找到.模块就是这个函数.

I also see forum-list.tpl.php file in forum directory, so I start to wonder when this file is called and where it gets data from, but all I can find in forum.module is this function.

function template_preprocess_forum_list(&$variables) 

我错过了什么吗?所以总的来说,我的问题是谁以及何时调用自定义注册的主题函数,比如 forum_list

Am I missing something? So in general my question is who and when invokes custom registered theme function, like forum_list

推荐答案

简单的答案是,如果您在主题目录中放置 mytheme-forum-list.tpl.php(其中 mytheme 是您的主题的名称)并对其进行自定义 drupal应该捡起来(先清除缓存).

Simple answer is if you in your theme directory put mytheme-forum-list.tpl.php (where mytheme is the name of your theme) and customise it drupal should pick it up (clear the cache first).

template_preprocess_forum 中的这一行调用了 Drupal 主题函数

This line in template_preprocess_forum calls the Drupal theme function

$variables['forums'] = theme('forum_list',
                              $variables['forums'],
                              $variables['parents'],
                              $variables['tid']);

这将引用 forum_theme() 中的行

This will reference the line in forum_theme()

  'forum_list' => array(
      'template' => 'forum-list',
      'arguments' => array('forums' => NULL, 'parents' => NULL, 'tid' => NULL),
    ),

告诉模板引擎寻找forum-list.php并提供参数.

Which tells the templating enging to look for forum-list.php and provides arguments.

如果您安装了 devel 模块 并打开主题开发者模块.这将向您展示 Drupal 在呈现内容时将寻找的所有候选模板和函数.

If you install the devel module and turn on the theme developer module. This will show you all of the candidate templates and functions which Drupal will look for when rendering content.

一般情况下(但有特定的例外)Drupal 会寻找最佳匹配模板并返回到预定义的函数.

In general (but with specific exceptions) Drupal looks for the best match template and falls back to the pre defined functions.

如果没有匹配项.查看主题指南,特别是关于覆盖主题化输出 你也可以找到 hook_theme 感兴趣.

if there is nothing that matches. Have a look at the theme guide and in specific the section on Overriding themable output you may also find hook_theme of interest.

这篇关于模块中的 Drupal 主题功能工作流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆