Drupal:将块分配给特定的内容类型

发布于 2024-08-29 13:34:46 字数 213 浏览 4 评论 0原文

我制作了一个名为 node-mynode.tpl.php 的自定义模板 每当请求 mynode 类型的节点时,就会生成 node-mynode.tpl.php 会自动使用。

然而,现在用户希望在这种情况下看到特定的菜单块。

问题: 如何将块分配给特定的内容类型?

提示:我已经开始使用 Pathauto 查看 URL 别名。 我怀疑一个解决方案可能就在这个方向上。

I made a customized template called node-mynode.tpl.php
Whenever a node of type mynode is requested, then node-mynode.tpl.php
is automatically used.

However, now user wants to see a specific menu block in this case.

Question:
How can I assign a block to a specific content type?

Hint: I have started to look at URL aliases with Pathauto.
I suspect one solution may lie in this direction.

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

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

发布评论

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

评论(3

茶底世界 2024-09-05 13:34:46

在 Drupal 6 中,您可以配置块的可见性设置。单击管理员后端中您的块旁边的“配置”链接,然后按照以下步骤操作 -

1) 选择“页面特定可见性设置”下的“显示以下 PHP 代码是否返回 TRUE(PHP 模式,仅限专家)”选项' 选项卡。

2) 输入以下 PHP 代码,检查当前节点的节点类型并相应返回 TRUE -

<?php 
   if( arg(0) != 'node' || !is_numeric(arg(1)) )
   { return FALSE;
   }

   //load a fully-populated Drupal node object
   $temp_node = node_load(arg(1));

   if( $temp_node->type == 'mynode' )       //check the node type
   {   return TRUE;    //display block
   }
?>

这应该可以工作......

In Drupal 6, you can configure the visibility settings of blocks. Click on the 'configure' link next to your block in the administrator backend and follow these steps -

1) Select the 'Show if the following PHP code returns TRUE (PHP-mode, experts only)' option under the 'Page specific visibility settings' tab.

2) Enter the following PHP code which checks the node type of the current node and returns TRUE accordingly -

<?php 
   if( arg(0) != 'node' || !is_numeric(arg(1)) )
   { return FALSE;
   }

   //load a fully-populated Drupal node object
   $temp_node = node_load(arg(1));

   if( $temp_node->type == 'mynode' )       //check the node type
   {   return TRUE;    //display block
   }
?>

This should work....

怀里藏娇 2024-09-05 13:34:46

您可以使用上下文模块

you can use the context module

风情万种。 2024-09-05 13:34:46

为所有 mynode 类型节点提供一个以 /mynode 开头的自动别名,并使用该块的页面特定可见性设置,仅在以 开头的页面上显示>/mynode/*

Give all of your mynode type nodes an automatic alias that starts with /mynode and use the page specific visibility settings for the block, showing only on the pages that start with /mynode/*.

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