Skip to content

Instantly share code, notes, and snippets.

@callumflack
Created January 22, 2016 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save callumflack/4f997ec1763552433c04 to your computer and use it in GitHub Desktop.
Save callumflack/4f997ec1763552433c04 to your computer and use it in GitHub Desktop.
Adding class to main menu based on whether or not a post has a certain tag
{% assign focus = site.pages.news.taxonomy.tags.focus-magazine %}
<li>
<a href="{{focus.url}}"
{% if url == focus.url %}class="is-selected"
{% elsif taxonomy.tags.all contains "focus-magazine" %}class="is-selected"
{% endif %}>
{{focus}}
</a>
</li>
{% assign flag = "false" %}
{% for tagset in site.pages.news.taxonomy %}
{% for tag in tagset %}
{% if tag.value == "focus-magazine" %}
{% assign flag = "true" %}
{% endif %}
{% endfor %}
{% endfor %}
<li>
<a href="{{focus.url}}"
{% if url == focus.url %}class="is-selected"
{% elsif type == "post" and parent.slug == news.slug and flag != "true" %}class="is-selected"
{% endif %}>
{{focus}}
</a>
</li>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment