3

I'm having trouble displaying a channel entry loop within my EE setup which uses the Stash and IfElse modules. First of all, see this screenshot of my file structure:

File structure (Inside templates folder)

I'm using the 'partials approach' (heavily based on this article) and therefore have an index.html file which handles my routing.

index.html:

{!-- If we're on one of the main support pages --}
{if segment_2!="" AND segment_3==""}
{embed="support/main-landing"}

{!-- If we're on one of the Financial Support sub-pages --}
{if:elseif segment_2=="financial-support" AND segment_3!=""}
{embed="support/main-detail"}

{/if}

So if we look at the main-landing template file, you can see that I'm specifying the stash layout file to use and also setting some variables - one for the actual landing page itself and the other for the loop I am having trouble displaying.

main-landing.html:

{stash:embed:layouts:support-main-landing}

{!-- Set data for the landing page --}
    {exp:channel:entries channel="support" url_title="{segment_3}"}
        {exp:stash:set}
            {stash:url_title}{url_title}{/stash:url_title}
            {stash:title}{title}{/stash:title}
            {stash:page_content}{page_content}{/stash:page_content}
        {/exp:stash:set}
    {/exp:channel:entries}

      {!-- Set data for the financial support sub-pages --}
      {exp:stash:set_list name="financial_support_options" parse_tags="yes"}
      {exp:channel:entries channel="financial_support"}
                {stash:financial_url_title}{url_title}{/stash:financial_url_title}
                {stash:financial_title}{title}{/stash:financial_title}
                {stash:financial_page_content}{page_content}{/stash:financial_page_content}
                {stash:financial_summary}{summary}{/stash:financial_summary}
     {/exp:channel:entries}
     {/exp:stash:set_list}

The following layout file then gets the loop that we just set, using get_list.

support-main-landing.html:

{stash:embed:wrappers:main} {!-- Select the main wrapper template --}


{exp:stash:set name="content"} {!-- Set everything in between here as the content --}
    {stash:embed:partials:breadcrumb}
    <div class="efc internal main-content">
        <div class="container entry">
            <div class="col-md-8">
                <h4>{exp:stash:get name='title'}</h4>
                <div class="row financial-options">
                    {exp:stash:get_list name="financial_support_options"}
                        <div class="col-md-6">
                            <p><strong><a href="financial-support/{financial_url_title}">{financial_title}</a></strong></p>
                            <p>{financial_summary}</p>
                        </div>
                    {/exp:stash:get_list}
                </div>
            </div>
            <div class="col-md-4">
                {!-- If we're on the Financial Support page, show it's unique sidebar --}
                {if segment_2=="financial-support"}
                    {stash:embed:content:sidebar-financial-support}
                {/if}
            </div>
        </div>
    </div>
{/exp:stash:set}

The Problem:

Everything seems to be working except for the loop financial_support_options. When the page is rendered, it manages to display the surrounding <div class="row financial-options"> but no data inside...so the problem must lie where I am actually setting the loop variable in main-landing.html.

FYI - The financial-support channel and support channel both use the same Channel Field Group

Do you absolutely HAVE to set the tags as stash variables in order to use them within the layout files in the stash folder?

Any help will be greatly appreciated!

1

Are you sure your channel entries tag is actually outputting anything for Stash to capture? I would suggest adding dynamic="no"

{exp:stash:set_list name="financial_support_options" parse_tags="yes"}
    {exp:channel:entries channel="financial_support" dynamic="no"}
        {stash:financial_url_title}{url_title}{/stash:financial_url_title}
        {stash:financial_title}{title}{/stash:financial_title}
        {stash:financial_page_content}{page_content}{/stash:financial_page_content}
        {stash:financial_summary}{summary}{/stash:financial_summary}
     {/exp:channel:entries}
 {/exp:stash:set_list}

If you turn on the Template Debugger you will be able to see lines beginning Stash: Look for the variable financial_support_options in the debug output to see what value Stash says it is set to.

Besides that advice, I'd question why you need to split main-landing and support-main-landing.html into two files? Are you using support-main-landing.html elsewhere? If not, why not make them one to simplify things?

{stash:embed:wrappers:main}

{!-- Set data for the landing page --}
{exp:channel:entries channel="support" url_title="{segment_3}"}
    {exp:stash:set}
        {stash:url_title}{url_title}{/stash:url_title}
        {stash:title}{title}{/stash:title}
        {stash:page_content}{page_content}{/stash:page_content}
    {/exp:stash:set}
{/exp:channel:entries}

{!-- Set data for the financial support sub-pages --}
{exp:stash:set_list name="financial_support_options" parse_tags="yes"}
     {exp:channel:entries channel="financial_support" dynamic="no"}
         {stash:financial_url_title}{url_title} {/stash:financial_url_title}
         {stash:financial_title}{title}{/stash:financial_title}
         {stash:financial_page_content}{page_content}{/stash:financial_page_content}
         {stash:financial_summary}{summary}{/stash:financial_summary}
     {/exp:channel:entries}
{/exp:stash:set_list}

{!-- Set everything in between here as the content --}
{exp:stash:set name="content"}
{snippet:breadcrumb}
<div class="efc internal main-content">
    <div class="container entry">
        <div class="col-md-8">
            <h4>{exp:stash:get name='title'}</h4>
            <div class="row financial-options">
                {exp:stash:get_list name="financial_support_options"}
                    <div class="col-md-6">
                        <p><strong><a href="financial-support/{financial_url_title}">{financial_title}</a></strong></p>
                        <p>{financial_summary}</p>
                    </div>
                {/exp:stash:get_list}
            </div>
        </div>
        <div class="col-md-4">
            {!-- If we're on the Financial Support page, show it's unique sidebar --}
            {if segment_2=="financial-support"}
                {stash:embed:content:sidebar-financial-support}
            {/if}
        </div>
    </div>
</div>
{/exp:stash:set}
| improve this answer | |
  • Thank you very much Mark! It's a complete coincidence that literally 2 minutes before your answer I tried the dynamic="no" idea and it fixed everything! You're right, I'm using support_main_landing elsewhere which is why they are split. Now I need to read into what exactly dynamic="no" does, because it seems that I don't need it at all. Perhaps there is a global setting to switch this off. Thanks for the template debug advise – remi90 Oct 23 '13 at 9:04
  • Ha! I couldn't tell you how many times that one's caught me out :) – Mark Croxton Oct 23 '13 at 9:05
  • Btw, If you have global elements like a breadcrumb trail, you really would be better off making them snippets (or low variables). It's the most efficient way to include them in your template. – Mark Croxton Oct 23 '13 at 9:07
  • Agreed, although the main reason why I avoided this was due to not having access to snippets via actual files? (I think this is what the Low Variables plugin is for) – remi90 Oct 23 '13 at 14:18
2

In main-landing.html wrap the stash:set pair around the entries tag pair.

{stash:embed:layouts:support-main-landing}

{!-- Set data for the landing page --}
{exp:stash:set parse_tags="yes"}
    {exp:channel:entries channel="support" url_title="{segment_3}"}
        {stash:url_title}{url_title}{/stash:url_title}
        {stash:title}{title}{/stash:title}
        {stash:page_content}{page_content}{/stash:page_content}
    {/exp:channel:entries}
{/exp:stash:set}
| improve this answer | |
  • That doesn't fix anything unfortunately. In fact, it breaks the variables for the support channel (which worked before). Is there any known issues when trying to stash:set and stash:set_list in the same file? Whilst also using the same variables? – remi90 Oct 23 '13 at 8:28
  • 1
    Sorry, forgot to add the parse_tags="yes" parameter. Here's a template from a site I recently built that's working: d.pr/gmEb Having stash:set and stash:set_list in the same file is not a problem as long as they're setup properly. – Stephen Callender Oct 23 '13 at 10:24

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.