0

I am trying to build out a list of categories that I need to include in the nav as well as other sections of a site. I had it done with embeds and {exp:category} loops, but I would rather be able to pull what I need using stash if possible.

I want to create two separate lists. One will be the locations (or parent categories. The second will be the category children. I need to be able to relate the category children. This is why I have the kid's list being created using the parent category name.

I am getting what I need by doing the following:

{!-- LOCATIONS --}
{exp:stash:set_list name="locations" parse_tags="yes"}
    {exp:channel:categories
        category_group='2'
        style='linear'
        parent_only='yes'
    }
        {stash:location}{category_name}{/stash:location}
        {stash:url}{category_url_title}{/stash:url}
    {/exp:channel:categories}
{/exp:stash:set_list}

{!-- LOCATIONS KIDS --}
{exp:stash:parse}
    {exp:channel:categories
        category_group='2'
        style='linear'
    }
        {if parent_id == '0'}
            {if count > '1'}
                {/exp:stash:set_list}
            {/if}
            {exp:stash:set_list name="{category_name}_kids" parse_tags="yes"}
        {if:else}
            {if count == total_results}
                    {stash:kid}{category_name}{/stash:kid}
                    {stash:kid_url}{category_url_title}{/stash:kid_url}
                {/exp:stash:set_list}
            {if:else}
                {stash:kid}{category_name}{/stash:kid}
                {stash:kid_url}{category_url_title}{/stash:kid_url}
            {/if}
        {/if}
    {/exp:channel:categories}
{/exp:stash:parse}

I can pull the locations manually, and I can pull the kids manually. What I NEED to be able to do is pull them dynamically by relationship. I tried this, but it doesn't render the kids.

{exp:stash:get_list name='locations'}
    <li class="dropdown-submenu">
        <a href="{site_url}find-your-home/{url}">{location} <b class="caret-right"></b></a>
        <ul class="dropdown-menu">
            {exp:stash:get_list name='{location}_kids'}
                <li>
                    <a href="{site_url}find-your-home/{url}/{kid_url}">{kid}</a>
                </li>
            {/exp:stash:get_list}
        </ul>
    </li>
{/exp:stash:get_list}

Is there something I am missing or can I not build out a dynamic list call?

  • On a side note: I could be wrong but, you might not need that exp:stash:parse tag if you add parse_conditionals to the set_list. – Natetronn Feb 23 '16 at 17:50
0

I think you need to take in account the fact that you're nesting.

{exp:stash:get_list name='locations'}
    <li class="dropdown-submenu">
        <a href="{site_url}find-your-home/{url}">{location} <b class="caret-right"></b></a>
        <ul class="dropdown-menu">
            {exp:stash:get_list:nested name='{location}_kids'}
                <li>
                    <a href="{site_url}find-your-home/{url}/{kid_url}">{kid}</a>
                </li>
            {/exp:stash:get_list:nested}
        </ul>
    </li>
{/exp:stash:get_list}
| improve this answer | |
0

I am dealing with the same situation, however some of the main menu items (parent categories) dont have children (sub categories)

How can I make the caret display conditionally only if there are sub menu items?

Thanks so much, this has helped me a lot already!

| improve this answer | |
  • This is what my issue was (in the end) as well. If you are using stash, just create a field as a flag and use logic to check for existence or not. If you aren't using stash, then check for them on THOSE particular nav segments and use them if needed. – W3bGuy Aug 31 '16 at 19:59

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.