I’ve got a page where I’m posting links to the groups that a user has access to based on Member Categories. Before, I just used the {exp:member_categories:categories} loop and it worked fine, but there was no organization to the way the list was displayed and it was just a long random list of links. So I’m trying something different and running a separate {exp:member_categories:check} for each of the categories, broken down into logical groups. Not the most efficient, I know, but it’s only on one page (and I can technically cache it when it’s done).

Anyway, the only problem is that I can’t give a single “you do not belong to any groups” if they don’t belong to any groups. If I do a {if no_results}, then I get that for each category that it checks. And I don’t really want that.

I was going to try to use Stash to set some sort of value to an append_list, then check that at the end. However, it’s not working. I have tried both of the following, setting a value of “1” so that I could check for “is_empty” later.

{exp:stash:append_list name="group_list" process="end"}
    {exp:member_categories:check category_id="113"}
        <p><a href="/members/groups/sample-group">Sample Group</a></p>
        {stash:item_link}1{/stash:item_link}
    {/exp:member_categories:check}
{/exp:stash:append_list}

and

{exp:member_categories:check category_id="113"}
    {exp:stash:append_list name="group_list" process="end"}
        <p><a href="/members/groups/sample-group">Sample Group</a></p>
        {stash:item_link}1{/stash:item_link}
    {/exp:stash:append_list}    
{/exp:member_categories:check}

I’m not sure if this is even possible? Or are there any other options?

Don't know much about member categories add-on, but seems you could do something like your first idea.

{!-- #1 Stash categories for member --}
{exp:member_categories:categories}
    {exp:stash:append_list 
        name="mcats" 
        context="{category_group}"
        parse_tags="yes"
    }
        {stash:cat_id}{category_id}{/stash:cat_id}
        {stash:cat_name}{category_name}{/stash:cat_name}
        {!--etc...--}
    {/exp:stash:append_list}
{/exp:member_categories:categories}

{!-- #2 Check if some cats exist for this member --}
{if {exp:stash:not_empty name="mcats"}}

    {!-- #3 Output Category ID 113 --}
    {exp:stash:get_list 
        name="mcats" 
        context="113"
        prefix="st"
    }
        {if st:no_results}<p>No Results for Category ID 113</p>{/if}
        <li>{st:test}</li>
    {/exp:stash:get_list}

{if:else}
    <p>No Results at all for this member</p>
{/if}

Untested. (You might need to wrap #1 or #2, both separately, or the whole thing with stash:parse if you don't get expected parsing results).

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.