Search code examples
drupal-7drupal-theming

drupal 7 Targeting specific arrays in a page.tpl.php


I have a situation where i need two different conditions to be met in order for the title of a given node to be printed to the page (this bit below is from my page.tpl):

<?php if 
($title && ($user->uid == 1) || $title && ($page['#object']['type']['blog_post'])
/* is the node a full blog post? */
): ?>

I want to display the title of a node only if the user is logged in. which is working, but i am not sure how to display the title for my specific node type. Obviously I am drilling down into the wrong part of the array. But I can't seem to figure out which part of the array will deliver to satisfy my condition.

thanks!


Solution

  • You can use $node variable in your page.tpl.php when diaplayed page is node. Node type stores in $node->type. But only for node pages. Node page of type 'blog_post' displays full blog post.

    <?php if(isset($node) && $node->type == 'blog_post');?>
      <?php print $title; ?>
    <?php endif?>
    

    In page.tpl will print title only on full nodes of your type.