0

So, I have a region, which should only display on a specific page. Is there a way to have a page-checking condition in the page template to only display the region on the specified page, or do I need to create a page specific .tpl file which should have the region in it?

The issue I'm having is that region is being added to pages without content in them. This is evident, because the CSS border property for the region is being applied despite their being no content in it. enter image description here. You can see in the images that there is border applied to the element, which shouldn't be loaded into the page. enter image description here Here is the relevant excerpt from my page.tpl

<div id="navigation">
  <div class="base-grid-container">
    <?php print render($page['navigation']); ?>
  </div>
</div>

<div id="page">

  <!-- B11: Don't display the message that content is needed on the front -->
  <?php if(drupal_is_front_page()) {unset($page['content']['system_main']['default_message']);} ?>

  <div id="header">
    <div class="base-grid-container">
      <div id="header-left">
        <?php if ($logo): ?>
          <a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home" class="header__logo" id="logo"><img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" class="header__logo-image" /></a>
        <?php endif; ?>
      </div>
      <div id="header-right">
        <?php print render($page['header']); ?>
      </div>
    </div>
  </div>

  <div id="main">
    <div id="hero">
      <?php print render($page['hero']); ?>
    </div>

    <div id="content" class="container">
      <div class="base-grid-container">
        <?php print render($page['highlighted']); ?>
        <?php print $breadcrumb; ?>
        <a id="main-content"></a>

        <?php print render($title_prefix); ?>
        <?php if ($title && !drupal_is_front_page()): ?>
          <h1 class="page__title title" id="page-title"><?php print $title; ?></h1>
        <?php endif; ?>
        <?php print render($title_suffix); ?>

        <?php print $messages; ?>
        <?php print render($tabs); ?>
        <?php print render($page['help']); ?>
        <?php if ($action_links): ?>
          <ul class="action-links"><?php print render($action_links); ?></ul>
        <?php endif; ?>
        <?php print render($page['content']); ?>
        <div id="blog_side">
          <?php print render($page['blog_sidebar']); ?>
        </div>
        <div class="blog-feed">
          <?php print $feed_icons; ?>
        </div>
      </div>

    </div>
6
  • Would something like that: drupal.org/node/2647050 help in your situation? You can have your code in a block that only shows on the page(s) you define.
    – webmaniac
    Commented Dec 3, 2016 at 17:50
  • Hi @webmaniac, this is almost totally done through the UI, I was just hoping to avoid having to create a separate views page .tpl, and thought it would be easier with a conditional statement...
    – nizz0k
    Commented Dec 3, 2016 at 18:07
  • Your page templates would print a region only if there's content in it ie a block where your content lives. Maybe a more specific suggestion is possible with more information about your specific issue and some code.
    – webmaniac
    Commented Dec 3, 2016 at 18:12
  • So, the region is being loaded into a page without any content in the region and css styles are being applied to the empty but present region on the page.
    – nizz0k
    Commented Dec 3, 2016 at 18:22
  • If you don't want the empty region to be printed you can use an if with !empty() for the content of the region?
    – webmaniac
    Commented Dec 3, 2016 at 19:09

1 Answer 1

0

So, there's multiple ways to approach this: 1) views theme preprocess functions; 2) creating a page specific tpl; 3) jquery/js hacks to only show the content on the specified pages.

For the sake of maintenance and simplicity, I chose to re-build the page as a basic page and add the necessary views to the page and add the region to a page specific tpl. I chose the basic page option for simplicity as well as simplifying other tasks down the line such as breadcrumbs. I copied the page.tpl.php, and renamed it page--my-node-id.tpl.php and flushed the theme registry, restoring the original page.tpl. Just an FYI, going the node page route forced me to set the display for the article class inserted into the page to none, to keep my styling the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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