Drupal: assign block to a specific content type
-
30-09-2019 - |
Question
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.
Solution
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/*
.
OTHER TIPS
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