1

I followed online tutorials and defined a new region in litejazz Drupal 7 theme info file as :

regions[content_share] = Content Bottom

and exposed the new block using the code below in node.tpl.php as :

<div class="clearfix clear"></div>
  <?php if (!empty($content['links']['node']['#links']) || !empty($content['links']['comment']['#links']) || !empty($content['links']['blog']['#links'])): ?>
    <div class="links">&raquo; <?php print render($content['links']); ?></div>
  <?php endif; ?>
      <?php if ($content_share): ?> //<<<<<<<<<<<- THIS LINE CAUSES WARNING
  <div>
    <?php print render($content_share); ?>
  </div>
<?php endif; ?>
  <?php if ($content['comments'] && ($page)) { ?>
    <?php print render($content['comments']); ?>
  <?php }; ?>

Now my logs are getting filled with following warning :

Notice: Undefined variable: content_share in include() (line 39 of /srv/bindings/ertr88c9reretrea25f7b405eeee/code/sites/all/themes/litejazz/templates/node.tpl.php).

I had tried clearing cache as suggested in other solutions but none worked.

2

Regions are only available in page.tpl.php, not node.tpl.php.

In page.tpl.php you can use

print render($page['content_share']);
  • The above outputs the region correctly for me but with the warning. I am not a drupal dev, what would be the correct code block for the above implementation? – MyPalDrupal Nov 28 '13 at 11:06
  • You won't get the warning using the above code (unless you're getting a different warning, about an undefined array index). Have you left print $content_share; in a template file somewhere? – Clive Nov 28 '13 at 11:14
  • @MyPalDrupal In these cases, put the blame on the Drupal cache; most of the times, you are sure to be right. :) – kiamlaluno Nov 28 '13 at 11:18
  • No, here are the relevant files : pastebin.com/2jabpa0F , pastebin.com/hcQSDptq and pastebin.com/bMbTjt2M – MyPalDrupal Nov 28 '13 at 11:20
  • In node.tpl.php you still have <?php if ($content_share): ?>. $content_share is not available in that context, so you get the warning – Clive Nov 28 '13 at 11:41
0

Check whether the region is available in the scope before assigning any value to it.

Check with get_defined_vars() in the node.tpl.php

var_dump(get_defined_vars());

Same issue is well explained in this thread

  • It can't be, regions aren't available in node.tpl.php – Clive Nov 28 '13 at 10:33
  • 1
    Hi Clive, I am not saying regions are available in node.tpl.php, just saying a good practice before using any variables in an unknown scope. – Bala Varadarajan Nov 28 '13 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.