4

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.

Layout/Wrapper:

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

        <section id="Sidebar" class="grid-1-3" role="complementary">
          {exp:stash:sidebar}
        </section> <!-- /END #Sidebar -->
      </div> <!-- /END wrapper grid -->
    </div> <!-- /END #Content -->
    {sn_global_footer}
  </body>
</html>

Partial:

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


{!-- 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"}
  {exp:channel:entries
    channel="ch_pages"
    limit="1"
    {global:param_disable_default}}
    {if page:no_results}{redirect="404"}{/if}
      {sn_global_edit_this}
      {if cf_page_feature_image}
        <figure id="Featured-Image">
          <img src="{cf_page_feature_image}" width="390" height="305" alt="Test figure" />
        </figure>
      {/if}

      <h1>
        {if cf_page_extended_page_title}
          {cf_page_extended_page_title}
        {if:else}
          {title}
        {/if}
      </h1>

      {if cf_page_body}
        {cf_page_body}
      {/if}
  {/exp:channel:entries}
{/exp:stash:set}

{!-- Sidebar --}
{exp:stash:set name="sidebar" parse_tags="yes" trim="yes" parse_conditionals="yes" no_results_prefix="sidebar"}
  {exp:channel:entries
    channel="ch_pages"
    orderby="random"
    limit="1"
    {global:param_disable_default}}
    {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" />
      {/if}

      <img src="{cf_header_image:medium}" alt="{title}" width="390" id="Header-Image" role="img" />
    {/reverse_related_entries}
  {/exp:channel:entries}
{/exp:stash:set}

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>
    {exp:low_reorder:entries
      set="lr_cac_pm"
      dynamic="no"
      {global:param_disable_default}}
      <div class="listing">
          {sn_global_edit_this}

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

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?

5

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

{embed="_layouts/.two-column"}

{snippet_common_page_elements}

{!-- Unique page code goes here --}
| improve this answer | |
  • 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! – Paulo Elias Mar 12 '13 at 23:35

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.