3

Is there a way to display a fallback snippet if a {categories show_group='xy'}-Tag is empty / a entry does not have a category?

The example…

<p>Category: {categories show_group='xy' backspace='2'}<a href='#'>{category_name}</a>, {/categories}</p>

… shows …

Category: 

… if there is no linked category for this entry in this category-group. Is there a way to do something like:

Category: No categories assigned

… or hide «Category: » in the first place with a conditional or something simpler than this kind-of-complicated stuff:

{categories show_group='xy' limit='1'}<p>Category: {/categories}{categories show_group='xy' backspace='2'}<a href='#'>{category_name}</a>, {/categories}</p>{categories show_group='xy' limit='1'}</p>{/categories}
7

I have used this, which isn't the most elegant solution, but does work:

{if "{categories show_group='xy'}y{/categories}" != ""}
    Category: {categories show_group='xy'} ... {/categories}
{if:else}
    No categories here
{/if}

You could also try the BW Category Count add-on.

0

I'd look at the count parameter as a conditional: http://ellislab.com/expressionengine/user-guide/modules/channel/categories.html#count

{categories show_group='xy' backspace='2'}
{if count == "1"}Category:{/if} // If there are any cat's then show the title
<a href='#'>{category_name}</a>,
{/categories}

It's late here and the code may not be perfect but you should get the gist :)

  • The {count} variable isn't available in the variable pair inside the {exp:channel:entries} tag. You're referring to the {exp:channel:categories} tag here. – Low Jan 17 '13 at 12:21
0

Was having the same problem. I wrote a small (free) plugin that will enable you to do just that. Entry id is mandatory and has optional category groups. Available here.

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.