检查页面是否在模板的首页


7

当用户位于drupal网站的首页时,如何只在模板中显示一个简单的首页检查?

我尝试了这个,但是最终崩溃了:

<?php function drupal_is_front_page() {?> <h1>TEST</h1> <?php } ?>

使用drupal网站上的if代替此功能是否可行?

谢谢!

Answers:


19

您不应在Drupal模板中声明函数。相反,您应该只引用该函数:

<?php
if (drupal_is_front_page()) {
    ?><h1>Test</h1><?php
}
?>

4
注意,如果您的模板是page.tpl.php的派生类,则您已经具有$is_front可用的变量
Clive

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.