0

I'm wanting to dynamically populate a switchee value, I've tried using an embed, but it seems the parse order means this won't work so I'm looking for aternative ideas, this is the code we've tried:

{exp:switchee variable="{segment_1}" parse="inward"}

    {case value="{embed='site/_school-list'}"}
        {redirect="/contribute/school/{segment_1}"}
    {/case}

    {case default="yes"}
        Otherwise go here   
    {/case}

{/exp:switchee}

Basically I want to automatically pull out all of the entries from the school channel and get their {url_title}, then check it against {segment_1}.

The code in the embed is:

{exp:channel:entries channel="schools" dynamic="no" limit="99999"}{url_title}|{/exp:channel:entries}

Which is outputting correctly when tested.

Any ideas?

4

While you could easily use Stash to pass the entry ids as a variable, you shouldn't.

To create the variable would mean iterating over the entire list of entries in a channel. That's expensive just for a simple routing operation.

Assuming this is being run on your site's default index template, and you have strict 404s disabled, why not just redirect if segment_1 exists at all?

{if segment_1 != ""}
 {redirect="/contribute/school/{segment_1}"}
{/if}

Your template contribute/school should take care of 404s using a channel entries tag with parameters require_entry="yes" and {if no_results}{redirect="404"}{/if}

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.