3

So my client has thrown a curve ball! I've set-up a list of categories for the types of work they cover. However, they DON'T want all of the categories to actually link to an entry. In other words, they don't have content for some of the category pages, they would still like to SHOW the category on the front end but not have it clickable.

So, some category links are clickable, others not :/

Any ideas?

Thanks

Martin

2

I think I might have found a solution, although it might not be very elegant :/

So, i'm basically looking to see if a category field has content and then taking out the anchor in the template.

{% if category.practiceIntroText|length %}
    <a href="{{ category.url }}">
{% endif %}
{{ category.title }}
{% if category.practiceIntroText|length %}
    </a>
{% endif %}

Same code but making use of the ternary operator:

{% set catWithContent = category.practiceIntroText|length %}

{{ catWithContent ? '<a href="' ~ category.url ~ '">' }}
{{ category.title }}
{{ catWithContent ? '</a>' }}
  • 1
    I think this is a good solution. Added a code variant that makes use of the ternary operator. – carlcs Sep 4 '15 at 12:32

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.