我在我的子主题页面--front.tpl文件中使用了这段代码,但我在首页上看不到任何像下面代码那样的消息。
<?php
$flag = drupal_is_front_page();
if ($flag) {
drupal_set_message("Welcome to front page of this site.");
}
else
{
drupal_set_message("Now you are in page other than front page.");
}
?>
https://api.drupal.org/api/drupal/modules!系统第.tpl.php/7页
https://drupal.org/node/39891
尝试$is_front
表达式:
<?php
if($is_front)
{
echo "you are on the front page";
}
else
{
echo "you are not on the front page";
}
尝试以下格式设置消息:
drupal_set_message(t("Welcome to front page of this site."));
page--front.tpl.php始终是首页!所以你不需要if语句!
如果你在另一个页面上,它会使用page.tpl.php!您应该在page.tpl.php.
消息将排队等待下一页,并且不会显示在当前页面上,因为drupal_set_message是在主题级别调用的,此时消息变量已经呈现。
因此,如果你访问了首页,然后转到另一个页面,那么"欢迎来到本网站的首页"的消息就会显示在另一个网页上。