By Jordash on
Let's say in page.tpl.php I want to detect which content type and print out a different block, depending on Content type:
if($contenttype='events'){
do this
}
how would I do something like that in the page.tpl.php file?
Thanks
Comments
if ( !empty($node) &&
does $node exist in
does $node exist in page.tpl.php? If I am not wrong, $node variable dies out after node.tpl.php is parsed. right? I agree that the above code will work for sure in node.tpl.php but doubtful for page.tpl.php.
In page.tpl.php, if the path
In page.tpl.php, if the path is of the form node/{nid} (or node/{nid}/*) $node is defined.
thanks nevets for taking time
thanks nevets for taking time to explain me this. you are superfast!
I was thinking of that way
I was thinking of that way but it doesn't seem like the cleanest way to do it, you'd think drupal would have exposed this type of variable it could come in very handy.
I don't think you can print out blocks in the node.tpl.php unless I'm missing something.
While one can print blocks in
While one can print blocks in page.tpl.php, it is not considered best practice.
It sounds like what you want to do is only show the block when the page is displaying content of type 'events'. You can do that by adding the block to the appropriate region, configuring the block and limiting visibility with PHP code. This code would work
That worked perfectly It does
@nevets
if ( !empty($node) && $node->type == 'events' ) {
// do that
}
That worked perfectly It does work in the page.tpl.php page
Thanks for the tip.