1

I am generating a url in a switchee statement, I want to be able to save that url for use in multiple places in a loop. This should be simple but nothing ever seems to be as easy as it should be in EE templates. How do I do this?

{exp:low_search:results query="{segment_2}" limit="10" }
  {if count ==  1}<ol>{/if}
    <li>
        {exp:switchee variable = "{channel_short_name}" }
            {case value="bikes"}
               {exp:stash:set name="url"} {embed="bikes/_bike_url" url_title="{url_title}" entry_id="{entry_id}"}{/exp:stash:set}
            {/case}

            {case default="Yes"}
                {exp:stash:set name="url"}{exp:transcribe:uri path='{comment_url_title_auto_path}'}{/exp:stash:set}
            {/case}
        {/exp:switchee}
        <span class="image">
            {embed="embeds/image" entry_id="{entry_id}" width="200"}
        </span>

        <a href="{exp:stash:get name="url"}">{title}</a>
    </li>
  {if count == total_results}</ol>{/if}
  {if no_results}No search results{/if}
{/exp:low_search:results}

Thanks,

Cory

1
  • Oof, you really need to refactor this I'm afraid. Using embeds inside tags that loop is a major problem - your database will get hammered with 20 instantiations of the template parser, not to mention the overhead of code inside the embeds. Keep an eye on the debugger and query count. Sorry it's not the answer you're looking for, but this is a bigger problem than your stash issue. (parse_tags="yes" will go some way to a solution, but will never work for the embed, since they are parsed last.) Also switchee requires parse="inward". May 2 '13 at 21:46
1

I cant guarantee this code will work as is but the approach is more valid. Separate content from layout, capture and stash the results then lay it out.

//Capture results & store results in a USER scoped list
{exp:stash:set_list name="results" scope="user" parse_tags="yes" prefix="myvar"}
    {exp:low_search:results query="{segment_2}" limit="10"}
        {stash:entryid}{entry_id}{/stash:entryid}
        {stash:urltitle}{url_title}{/stash:urltitle}
        {stash:channel}{channel}{/stash:channel}
        {if myvar:no_results}No search results{/if}
    {/exp:low_search:results}
{/exp:stash:set_list}

//Get the list - lay it out
{exp:stash:get_list name="results" scope="user" prefix="myvar" process="end"}
    {if myvar:count=="1"}<ol>{/if}
    <li>
    {exp:switchee variable = "{channel}" parse="inward"}
    {case value="bikes"}
        <span class="image">
            {embed="embeds/image" entry_id="{entryid}" width="200"}
        </span>
        //This could be problematic, parsing and embed inside a case inside a stash
        <a href="{embed='bikes/_bike_url' url_title='{urltitle}' entry_id='{entryid}'}">{url title}</a>
    {/case}

    {case default="yes"}
        <span class="image">
            {embed="embeds/image" entry_id="{entryid}" width="200"}
        </span>
        //This could be problematic, parsing and embed inside a case inside a stash
        <a href="{exp:transcribe:uri path='{comment_url_title_auto_path}'}>{url title}</a>
    {/case}
    {/exp:switchee}
    </li>
    {if my_var:count == my_var:total_results}</ol>{/if}
    {if my_var:no_results}No Results{/if}
{/exp:stash:get_list}
0

Try adding process="end" to your exp:stash:get call, it's likely getting called prior to the switchee tag, rendering blank because it technically hasn't been set yet.

1
  • That did not seem to work. The whole tag breaks and spits out every template var to the page. :(
    – Cory Gwin
    May 2 '13 at 16:18

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.