I am curious to know if there are any "best practices" for using Stash to deal with "pages" that pull extra/additional channel entries that are pulled into the same wrapper/layout. More specially, do you put your conditionals in the layout itself? Or keep them in the partial?

As a quick example, say you use Structure and manage site with "static" pages that share the exact same layout. The only differencees are some pages have to pull in bios or show a map below the page content.


FILE: _layouts/.two-column.html
TYPE: Template
DEPENDENCIES: Librar-ee, Stash
DESCRIPTION: Two column wrapper template that holds interior page content
============================================================================ --}
<!DOCTYPE html>
<body id="{exp:stash:body_id}" class="{exp:stash:body_class}">
    <div id="Content">
      <div class="wrapper grid">
        <section id="Content-Primary" class="grid-2-3" role="main">
          <article class="module" role="article">
          </article> <!-- /END module -->
        </section> <!-- /END #Content-Primary -->

        <section id="Sidebar" class="grid-1-3" role="complementary">
        </section> <!-- /END #Sidebar -->
      </div> <!-- /END wrapper grid -->
    </div> <!-- /END #Content -->


{!-- ===========================================================================
  FILE: _partials/static-page.html
  TYPE: template partial
  DEPENDENCIES: Librar-ee, Stash, Channel Images
  DESCRIPTION: Services page partial
============================================================================ --}
{!-- Select layout ========================================================= --}

{!-- Set variables ========================================================= --}
{exp:stash:set name='body_id'}{/exp:stash:set}
{exp:stash:set name='body_class'}subpage two-col{/exp:stash:set}

{!-- Models ================================================================ --}
{!-- Content Primary --}
{exp:stash:set name="content_primary" parse_tags="yes" trim="yes" parse_conditionals="yes" no_results_prefix="page"}
    {if page:no_results}{redirect="404"}{/if}
      {if cf_page_feature_image}
        <figure id="Featured-Image">
          <img src="{cf_page_feature_image}" width="390" height="305" alt="Test figure" />

        {if cf_page_extended_page_title}

      {if cf_page_body}

{!-- Sidebar --}
{exp:stash:set name="sidebar" parse_tags="yes" trim="yes" parse_conditionals="yes" no_results_prefix="sidebar"}
    {if sidebar:no_results}<p>Sidebar content is not available.</p>{/if}

      {reverse_related_entries channel="ch_page_header_images"}

      {if no_reverse_related_entries}
        <img src="/assets/img/site/featured/placeholder-city.png" alt="CAC Real Estate Management Co., Inc." width="390" id="Header-Image" role="img" />

      <img src="{cf_header_image:medium}" alt="{title}" width="390" id="Header-Image" role="img" />

Where would you add the following extra bit of content that goes inside the main content area but below normal page content?

Additional content (on select pages):

{if last_segment == "project-management"}
  <article class="module" role="article">
    <h3>Project Management Team</h3>
      <div class="listing">

          <img src="{cf_bio_photo:headshot_sm}" alt="{title}" />
          <h4 class="bio-heading"><a href="{page_url}">{title}, {cf_bio_position}</a></h4>
            {exp:eehive_hacksaw words="100" append="&hellip; | <a href='{page_url}'>Read More &rarr;</a>"}
      </div> <!-- /END listing -->
  </article> <!-- /END module -->

Would you:

  • user conditionals and add it to the existing page partial? This way the 4-5 pages with extra content share one partial
  • create a new partial for each page with the additional content, use snippets to abstract the shared page content in the above partial, and keep it out of the original partial above?

My gut is to:

  • Create snippets for the shared content that is shared for every page
  • Create new partials for the unique pages with additional content and use the shared snippets inside these partials
  • Then, in the layout, use conditionals to display the extra content as needed.

It seems "dirtier" to have conditionals in the base partial to pull the extra data and then have conditionals to display the content in the layout as needed. Thoughts?

1 Answer 1


Personally, I tend to use separate templates and then do:



{!-- Unique page code goes here --}
  • Excellent, thanks! I started down this route while waiting for people to chime in and extracted all of the shared code (between pages) into snippets. Working great so far! Mar 12, 2013 at 23:35

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.