views:

426

answers:

3

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.

A: 

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

Finbarr
Brilliant! ! ! !
bert
... but not practical.. I have over 500 nodes of this type now and hundreds more to come. Is there another approach?
bert
Why is it not practical? You can delete any url aliases you have set for the nodes, then bulk generate aliases for all of them at once using your path replacement patterns. Typically something like `mynode/[title-raw]`.
Finbarr
My error. This solution does work. Url Alias module was able to re-alias old nodes and new ones are properly aliased. I have an automated batch feed and that works as well!
bert
I would not recommend this method. Path aliases are meant for usability and SEO, not for site building. A node with alias 'mynode/node-title' will still be available at 'node/123' but the block will not be rendered on that page.Once you go down this road, you can not safely grant users the right to define custom aliases anymore, because they might break your block visibility approach.
marcvangend
There's a module for that - global redirect. It will check for other aliases of any node and redirect to the user defined path alias.And yes, you cannot give your users the ability to set custom aliases when you go down this road. But why would you want to anyway? Do you want your users to create crazy urls like `example.com/this/site/really/sucks/so/much/i-hate-it`?
Finbarr
+2  A: 

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

gjhf
Side note: this has been possible since Drupal 4.7. For more information about using PHP for block visibility and lot of code examples, see http://drupal.org/node/60317.
marcvangend
+1  A: 

you can use the context module

wapnik