1

I have the following code:

{exp:channel:entries uri_page="{last_segment}"}
<!--Set some stash variables here, then:-->
    {exp:stash:set name="content"}
    <!--Some markup here, then:-->
          <section class="container">
            <h3>
              Related Articles
            </h3>
            <ul>
              {related_articles}
                <li>
                  <h4>{related_articles:title}</h4>
                  <p>
                    {related_articles:excerpt}
                    <a class="action" href="#">Continue reading</a>
                  </p>
                </li>
              {/related_articles}
            </ul>
          </section>
    <!--Some more markup.-->
    {/exp:stash:set}
{/exp:channel:entries}

Yet the relationship tags aren’t parsed at all. The output is:

  <section class="container">
    <h3>
      Related Articles
    </h3>
    <ul>
      {related_articles}
        <li>
          <h4>{related_articles:title}</h4>
          <p>
            {related_articles:excerpt}
            <a class="action" href="#">Continue reading</a>
          </p>
        </li>
      {/related_articles}
    </ul>
  </section>

I’ve made sure that the relationship field is named correctly ({related_articles}) and that the related articles are saved to the entry. All the other fields in the entry are parsed correctly in my template; only the relationships don’t get parsed.

I tried adding channel="channel_name" to the exp:channel:entries tag, thinking maybe EE needs to have a specific channel set in order for Relationships to work, but to no avail. I’ve also confirmed that the Relationships field type is installed (which is confirmed by the fact that I was able to create the field in the first place, but I’m grasping at straws here).

I’ve searched far and wide, and have been unable to find a solution to this, nor anybody reporting the same issue. Any help will be greatly appreciated!

1
  • 1
    This issue is solved. Although the answers by Stephen Callender and Mark Croxton certainly helped clean up and organize my code more efficiently, this particular issue was caused by a stray {/related_articles} further below in the markup. This was the product of a copy/paste in which I changed the opening tag but probably got distracted and missed the closing tag, causing hours of grief. So, if you’re having the issue of relationship tags not being parsed at all, make sure you don’t have any extra closing tags below it from having hastily copied and pasted it.
    – Alfonso
    Oct 18, 2013 at 16:02

2 Answers 2

2

uri_page="{last_segment}" is not a valid parameter for channel entries. You're looking for url_title I imagine :)

{exp:channel:entries url_title="{last_segment}"}
  {exp:stash:set_list name="related_articles"}
    {related_articles}
      {stash:rel_title}{related_articles:title}{/stash:rel_title}
      {stash:rel_excerpt}{related_articles:excerpt}{/stash:rel_excerpt}
    {/related_articles}
  {/exp:stash:set_list}
{/exp:channel:entries}

{!-- in the same template --}
{exp:stash:get_list name="related_articles" process="end"}
  {rel_title}
{/exp:stash:get_list}

{!-- in an EE or Stash embed --}
{exp:stash:get_list name="related_articles"}
  {rel_title}
{/exp:stash:get_list}

Module tags in EE templates are parsed recursively from the outside in, like the layers of an onion, and that's why you need to use process="end" to access variables set inside a tag pair but accessed from the outer root layer of the template. See my slides here for a demonstration of what this means in practice: https://speakerdeck.com/croxton/stash-core-principles?slide=18

4
  • Dangit, Mark! :) Oct 18, 2013 at 12:16
  • Thank you, Mark! I’m still getting the same output. I’ve refactored the code to include absolutely all markup on the stash partial, and my actual template only setting stash variables to be brought over to the partial. And again: every single part of the entry is parsed, except for the relationship fields.
    – Alfonso
    Oct 18, 2013 at 15:36
  • Just as an experiment, I created a separate template that only has {exp:channel:entries}{related_articles}{related_articles:title}{related_articles:excerpt}{/related_articles}{/exp:channel:entries} and assigned that template to the entry. I reloaded the page and the entry titles and excerpts are parsed correctly. Perhaps it’s a stash issue?
    – Alfonso
    Oct 18, 2013 at 15:41
  • I got it! Turns out I had copy/pasted my related_articles code to create a related_events section just below it, and I had failed to change the closing tag to related_events. Even though I had commented out this markup with EE comment tags ({!-- --}), it was apparently screwing up the parsing.
    – Alfonso
    Oct 18, 2013 at 15:50
1

In your Stash tag, you probably need to add the parse_tags="yes" parameter.

{exp:channel:entries uri_page="{last_segment}"}
<!--Set some stash variables here, then:-->
    {exp:stash:set name="content" parse_tags="yes"}
    ....

UPDATE

Separate your queries from your markup.

{exp:channel:entries uri_page="{last_segment}"}
  {exp:stash:set}
    {stash:title}{title}{/stash:title}
    {stash:custom_field_1}{my_custom_field}{/stash:custom_field_1}
    {!-- do this for all of the fields you'll need --}
  {/exp:stash:set}

  {exp:stash:set_list name="related_articles" parse_tags="yes"}
    {related_articles}
      {stash:rel_title}{related_articles:title}{/stash:rel_title}
      {stash:rel_excerpt}{related_articles:excerpt}{/stash:rel_excerpt}
    {/related_articles}
  {/exp:stash:set_list}
{/exp:channel:entries}

Then apply the Stash fields to the markup below on the same template or Stash embed:

<h1>{stash:title}</h1>
{stash:custom_field_1}
<section class="container">
    <h3>
      Related Articles
    </h3>
    <ul>
      {exp:stash:get_list name="related_articles"}
        <li>
          <h4>{rel_title}</h4>
          <p>
            {rel_excerpt}
            <a class="action" href="#">Continue reading</a>
          </p>
        </li>
      {/exp:stash:get_list}
    </ul>
  </section>
3
  • Thanks, Stephen. Unfortunately, this did not work. I get precisely the same output: all tags are parsed except for the {related_articles} tags.
    – Alfonso
    Oct 17, 2013 at 18:36
  • Thanks again for the update! Still not working. The above results in the same output, except it only shows the {related_articles:title} and {related_articles:excerpt} tags without the {related_articles} tags (of course, since they’re inside {exp:stash:set_list}).
    – Alfonso
    Oct 17, 2013 at 19:52
  • Oh, additionally: stash variables set as above return blank further down on the same template.
    – Alfonso
    Oct 17, 2013 at 19:54

Your Answer

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

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