Can anyone shed any light on why the following doesn't work for getSegment(2) but the previous does for getSegment(1)?

URL structure for these two examples are:



 <a class="button button--outline-blue {% if craft.request.getSegment(1) == 'blog' %}current{% endif %}" href="/blog">All</a>

{% nav category in craft.categories.group('blogCategories') %}

    <a class="button button--outline-blue {% if craft.request.getSegment(2) == 'trends' %}current{% endif %}" href="{{ category.url }}">{{ category.title }}</a>

{% endnav %}
  • What do you see if you you {{ dump(craft.request.getSegment(2)) }} on the /blog/trends page? Any chance the result you are seeing has to do with CSS styles? I expect when you say it doesn't work you mean the current class is not being added to the a tag in the second example. Nov 1 '15 at 15:16
  • Urgh ignore that question it is working I was just using the wrong template! Face Palm I do have a follow up question on how to make what I've used in the example as 'trends' to be the category title? I've tried what's been updated in the question.
    – sarah3585
    Nov 1 '15 at 15:30
  • 3
    Can you add an official answer to your original question and post your follow-up as a new question?
    – Brad Bell
    Nov 1 '15 at 17:04

Code above is fine. I was stupidly updating the wrong template

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.