简体   繁体   English

自定义模板的Drupal 6预处理功能

[英]Drupal 6 preprocess function for custom template

I have a custom template file I'm using for a page. 我有一个用于页面的自定义模板文件。

Say the page is www.mydomain.com/hello-world The content of this page is taken from a template file called hello-world.tpl.php 假设页面为www.mydomain.com/hello-world,此页面的内容取自名为hello-world.tpl.php的模板文件

Now I need to have a variable prepared in advance for that page, so I took a look at how core modules achieve this and tried to implement in the same way, only the variables are always null.. 现在,我需要为该页面预先准备一个变量,因此我看了看核心模块如何实现这一点,并尝试以相同的方式实现,只有变量始终为空。

for hello-world.tpl.php I created in my module file a function called: 对于hello-world.tpl.php,我在模块文件中创建了一个名为:

function template_preprocess_hello_world(&$variables) {
$variables['test'] = "test";
}

As I said $test doesn't get any value on www.mydomain.com/hello-world (I receive NULL when var dumping it) 正如我所说的,$ test在www.mydomain.com/hello-world上没有任何价值(当var转储它时,我会收到NULL)

I spent an hour or so double checking that I don't have any typos or anything like that. 我花了一个小时左右的时间仔细检查,确认我没有错字或类似的东西。

Is what I'm doing worng?? 这是我在做什么吗?

Try renaming the function to mymodulename_preprocess_hello_world(&$variables). 尝试将函数重命名为mymodulename_preprocess_hello_world(&$ variables)。 Don't forget to clear the cache as well. 不要忘记也清除缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM