1

I have this code fragment that works in a template when running EE2, but fails when the same template is run under EE3. I can't work out why. Would value any guidance anyone can give about how to fix. The fragment is:

{exp:stash:category_image parse="yes" trim="yes" output="yes"}
    {exp:category_construct:categories entry_id="{what_we_do_item_selector:image_button_switcher:entry_id}"}
        {if construct:level_count == "1"}
            {exp:channel:categories show="{construct:cat_id}" style="linear"}
                {category_image}
            {/exp:channel:categories}
        {/if}
    {/exp:category_construct:categories}
{/exp:stash:category_image}

which sets a value that is retrieved later within the same template using

{exp:stash:get name="category_image"}

It is a bit messy because category:construct cannot limit its output to a single entry using a tag parameter, and it is difficult to retrieve the category_image for a channel entry.

I am aware that the stash tag uses the 'short form' tag - but weirdly if I replace this with the long form tag, the tag fails in both EE2 and EE3.

This suggests I'm doing something that is probably illegitimate, but I cannot see what it is.

Anyhow - if anyone has any ideas about how I can capture the category_image URL more efficiently I'd be pleased to hear.

Thanks in advance for whatever help you can provide.

For clarity, I'm using EE2.11.3 / EE3.4.6 and Stash 3.0.4

2

One obvious problem there is that that you are parsing only one layer down when capturing the Stash variable. So you would actually be capturing this:

{exp:channel:categories show="{construct:cat_id}" style="linear"}
   {category_image}
{/exp:channel:categories}

Rather than the value of that tag.

Parse deeper by setting a parse_depth when you set the variable:

{exp:stash:category_image parse="yes" trim="yes" output="yes" parse_depth="2"}
 ...

Other than that it's possible that another tag in your template is malformed and breaking the parser. Try the above on it's own in a template. Turn on template debugging and look for a line beginning Stash: SET category_image ... to verify that the value you want is being captured.

| improve this answer | |
  • Ahah - helpful. Looks like (if I am reading the logs correctly) that stash is processing the enclosed tags in 'outward' direction - i.e. processing the channel:categories tag first - which fails because the cat_id is at that point unknown. Is there a way to force processing to be 'inward'? - tried adding parse="inward" to the stash tag but this had no effect. – JCOGS Design Dec 16 '16 at 11:54
  • Here is the debug output 9.833452 / 21.4MB Calling Tag: {exp:stash:category_image parse="yes" trim="yes" output="yes"} 9.833629 / 21.4MB Stash: processing inner tags 9.833832 / 21.4MB Calling Extension Class/Method: Stash_ext/stash_fetch_template 9.834719 / 21.4MB Nested Plugins in Tag, Parsing Outward First 9.835009 / 21.4MB Calling Tag: {exp:channel:categories show="{construct:cat_id}" style="linear"} 9.847078 / 21.4MB -> Data Returned – JCOGS Design Dec 16 '16 at 11:56
  • Got there in the end - added parse="inward" to the category_construct tag and that nailed it. Phew! – JCOGS Design Dec 16 '16 at 13:08

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.