Drupal: assign a block to a specific content type
I created a custom template called node-mynode.tpl.php Whenever a node like mynode is requested, node-mynode.tpl.php is automatically used.
However, the user now wants to see a specific menu block in this case.
Q: How do I assign a block to a specific content type?
Hint: I started looking at URL aliases with Pathauto. I suspect one solution may lie in this direction.
a source to share
In Drupal 6, you can customize block visibility settings. Click the "configure" link next to your block in the admin backend and do the following:
1) Select "Show if the following PHP code returns TRUE (PHP mode only, experts only)" on the Page 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.
a source to share