开发者

Drupal: assign block to a specific content type

开发者 https://www.devze.com 2022-12-27 19:03 出处:网络
I made a customized template called node-mynode.tpl.php Whenever a node of type mynode is requested, then node-mynode.tpl.php

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 UR开发者_如何学运维L aliases with Pathauto. I suspect one solution may lie in this direction.


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


you can use the context module


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/*.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号