Drupal 主题功能模块中的工作流程

发布于 2024-08-03 01:47:33 字数 568 浏览 2 评论 0原文

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

forum.module 文件包含 forum_theme 函数,用于控制该模块的主题设置方式 并且有这一行

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

我还在论坛目录中看到 forum-list.tpl.php 文件,所以我开始想知道这个文件何时被调用以及它从哪里获取数据,但我可以在论坛中找到所有内容.module就是这个函数。

function template_preprocess_forum_list(&$variables) 

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

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

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),
),

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) 

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

水溶 2024-08-10 01:47:33

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

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

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

这将引用 forum_theme() 中的行,

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

该函数告诉模板引擎查找 forum-list.php 并提供参数。

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

一般来说(但有特定的例外)Drupal 会寻找最佳匹配模板并回退到预定义的函数。

如果没有任何匹配的内容。查看主题指南,特别是覆盖主题输出 您还可以找到hook_theme

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).

This line in template_preprocess_forum calls the Drupal theme function

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

This will reference the line in forum_theme()

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

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

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.

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文