Voog.com

Tag

Represents single tag associated with an article. Tags for the given article can be rendered by iterating over a list of tags:

For editing in article:

{% if editmode %}
  {% editable article.tags %}
{% else %}
  {% for tag in article.tags %}
    {{ tag.name }}
  {% endfor %}
{% endif %}

By combining filters, there are shortcuts to render the list of tag names:

{{ article.tags | sort: "name" | map: "name" | join: ", " }}

For getting all site tags and generating tag clouds, have a look at the site object.

Attributes

id

Returns the ID of the tag.

name

Returns the name of the tag.

path

Returns the URL path of the tag.

Example of generating a tag list next to article that links to the blog page with some articles filtered out by tags:

{% for tag in article.tags %}
  <a href="/{{ article.page.path_with_lang }}/tagged/{{ tag.path }}">{{ tag.name }}</a>
{% endfor %}

to_json

Serializes the tag into a JSON string.

On blog listing page

On blog listing page an object name tags is present and if blog listing page is displayed with tag filter this returns the filter of tags.

{% if tags %}
  {% if tags == empty %}
    {{ "no_posts_tagged" | lc }}
  {% else %}
    {{ "posts_tagged" | lc }} '{{ tags | sort: "name" | map: "name" | join: "', '"}}'.
  {% endif %}
{% endif %}

Example of generating links of blog related tags on blog listing page and matching with tags in filter that are actively selected:

{% if blog.has_tags? %}
  
  {% comment %}Get the names of selected tag filters to an array.{% endcomment %}
  {% if tags %}
    {% assign selected_tags = tags | map: "name" %}
  {% endif %}
  
  {% comment %}Render list of links to tags in blog. Display active class if matches an active tag filter{% endcomment %}
  {% for tag in blog.tags %}
    <a {% if selected_tags contains tag.name %}class="active"{% endif %} href="/{{ blog.page.path_with_lang }}/tagged/{{ tag.path }}">{{ tag.name }}</a>
  {% endfor %}
{% endif %}