1

I have the following code, and the stash variable doesn't seem to parse. I believe it's an issue with parse order. Apologies, this is the first time I've used stash. I'm trying to show a multiple entry page filtered by categories sent from a HTML form:

<form action="" method="post">
    <input type="checkbox" value="62" name="recipe_type_categories[]">
    <input type="checkbox" value="63" name="recipe_type_categories[]">
    <input type="checkbox" value="59" name="recipe_type_categories[]">
    <input type="checkbox" value="64" name="recipe_type_categories[]">
    <input type="checkbox" value="61" name="recipe_type_categories[]">
    <input type="checkbox" value="60" name="recipe_type_categories[]">
    <input type="hidden" name="XID" value="{XID_HASH]">
    <input type="submit" name="submit" value="GO!">
</form>

An array of category IDs are POSTed to the page, it then sets the ids to a stash variable.

 {exp:stash:get name="recipe_type_categories" dynamic="yes" save="yes"}

My template looks like this:

{exp:channel:entries channel="recipes" dynamic="no" 
limit="18" uncategorized_entries="no" 
disable="member_data|comments|category_fields" 
category="{exp:stash:recipe_type_categories}" 
status="not Closed" paginate="both"}

{title}

{paginate}
    {pagination_links}
        <span>page {current_page} of {total_pages}</span>
        <ul>
        {first_page}
            <li><a href="{pagination_url}" class="page-first">first</a></li>
        {/first_page}

        {previous_page}
            <li><a href="{pagination_url}" class="page-previous">&lt;</a></li>
        {/previous_page}

        {page}
            <li><a href="{pagination_url}" class="page-{pagination_page_number} {if current_page}active{/if}">{pagination_page_number}</a></li>
        {/page}

        {next_page}
            <li><a href="{pagination_url}" class="page-next">&gt;</a></li>
        {/next_page}

        {last_page}
            <li><a href="{pagination_url}" class="page-last">last</a></li>
        {/last_page}
    </ul>
    {/pagination_links}
{/paginate}
{/exp:channel:entries}

Unfortunately, I see this in template debugging:

(0.012391 / 8.23MB) Tag: {exp:channel:entries channel="recipes" dynamic="no" limit="18" uncategorized_entries="no" disable="member_data|comments|category_fields" category="{exp:stash:recipe_type_categories}" status="not Closed" paginate="both"}

Hopefully someone can suggest a solution.

0

The standard way of handling this is with the Dynamic Parameters parameter - have you tried this instead of Stash? http://ellislab.com/expressionengine/user-guide/add-ons/channel/dynamic_parameters.html

==== Edit to add alternatives ====

Here's how the Stash approach could work. I've tested this and it seems to work fine for me. (You need to use parse="inward"):

<form action="" method="post">
    <input type="checkbox" value="62" name="recipe_type_categories[]">
    <input type="checkbox" value="63" name="recipe_type_categories[]">
    <input type="checkbox" value="59" name="recipe_type_categories[]">
    <input type="checkbox" value="64" name="recipe_type_categories[]">
    <input type="checkbox" value="61" name="recipe_type_categories[]">
    <input type="checkbox" value="60" name="recipe_type_categories[]">
    <input type="hidden" name="XID" value="{XID_HASH}">
    <!-- (note you should use {csrf_token} instead of {XID_HASH} in EE 2.8+) -->
    <input type="submit" name="submit" value="GO!">
</form>

{exp:channel:entries
    channel="recipes"
    dynamic="no"
    limit="18"
    uncategorized_entries="no"
    disable="member_data|comments|category_fields"
    category="{exp:stash:get name='recipe_type_categories' dynamic='yes' save='yes'}"
    paginate="both"
    parse="inward"
}
    <li>{title}</li>
    {paginate}...{/paginate}
{/exp:channel:entries}

If pagination is still a problem you might consider some alternative solutions:

  1. Native advanced search form
  2. Reefine add-on
  3. Low Search or Solspace SuperSearch add-ons
3
  • Unfortunately, I've come across dynamic parameters before and they don't appear to work with pagination - which is why I'm trying to use stash. In the notes section of that page it says "NOTE: If you have pagination links on your page they will not retain the page layout options created dynamically using this feature."
    – Paul Macey
    May 31 '14 at 23:14
  • Ah right yes, pagination can't really work with dynamic parameters without some JS trickery to force a re-POST. Have added some alternative answers. The Stash approach seems to work ok for me above. Jun 1 '14 at 10:32
  • Perfect, thanks James, that's done the trick - I had been adding the parse inward to the stash tag, but seeing it on the channel entries tag makes so much sense. Also thank you for alerting me to csrf token too, and those excellent addons.
    – Paul Macey
    Jun 1 '14 at 17:48

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.