Question

I'm trying to write an if statement in page.tpl.php to say:

If nodeid == 51, 52, 53 print:

<div class="band main-content">
 <?php print render($page['content']); ?>
</div>

Else print:

<div class="band main-content">
  <section class="layout">
   <?php print render($page['content']); ?>
  </section>
</div>
Was it helpful?

Solution 2

The condition you're looking for is in_array($nid, array(51, 52, 53)) (or you could use a bunch of logical ORs).

Putting it all together yields:

<?php if(in_array($nid, array(51, 52, 53))): ?>
  <div class="band main-content">
    <?php print render($page['content']); ?>
  </div>
<?php else: ?>
  <div class="band main-content">
    <section class="layout">
      <?php print render($page['content']); ?>
    </section>
  </div>
<?php endif; ?>

Also, I'm not sure what the end goal is here, but I would be wary about hard coding node IDs in a template. It's definitely not best practice.

OTHER TIPS

I haven't tested this, but it should work:

<?php
 if ($node) {
     // Get the current node nid
     $nid = $node->nid;
 }

//now compare the current node id present in $nid with some node ids you desire that you can put in $desired_node

$desired_node = array(51,52,53);  //enter your desired node ids

if (in_array($nid, $desired_node)){        
print render($page['content']); 
}

if (!in_array($nid, $desired_node)){ ;?>
<section class="layout">
 <?php print render($page['content']); ?>
</section>
<?php } ;?>

I am not sure how do you get an array in $nid, but instead, you should call a function, written in a custom module. That function should check the current nid by taking it from the URL and return either TRUE of FALSE. In any cases, (other than known nodes), you should add logic in a function, defined in a custom module. This helps debugging & enhancements.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top