Daniel Dobiášovský
Member
First Post
Conversation Starter
24 posts
I cant find solution for separation tags or categories, taxonomy list if i show page tags for example with this:
{% if page . taxonomy . tag %}
{% for tag in page . taxonomy . tag %}
{{ tag }}
{% endfor %}
{% endif %}
And i have tag like this:
Alfa Beta Gama
I want put the separator for this:
Alfa, Beta, Gama
I find solution with twig "join" but this is not work i need this:
{% if page . taxonomy . tag %}
{% for tag in page . taxonomy . tag %}
{{ tag | join ( ' , ' ) }}
{% endfor %}
{% endif %}
Knows this someone? I try to find in docs and everything must work but somewhare is problem and i dont know whare...
Thank you guys!
last edited 08/09/21 by Daniel Dobiášovský
P
pamtbaau
Grav Forum Moderators
Legend
First Post
Conversation Starter
Well Liked
3127 posts
@Deight, Please have a look at the Twig documentation about join to get a basic understanding of how the filter works.
Here are some examples from the Twig docs:
{{ [1, 2, 3]|join }}
{# returns 123 #}
{{ [1, 2, 3]|join('|') }}
{# outputs 1|2|3 #}
{{ [1, 2, 3]|join(', ', ' and ') }}
{# outputs 1, 2 and 3 #}
Since page.taxonomy.tag is an array, the following will solve your issue:
Replace:
{% if page . taxonomy . tag %}
{% for tag in page . taxonomy . tag %}
{{ tag | join ( ' , ' ) }}
{% endfor %}
{% endif %}
with:
{{ page . taxonomy . tag | join ( ' , ' ) }}
last edited 08/11/21 by pamtbaau
P
pamtbaau
Grav Forum Moderators
Legend
First Post
Conversation Starter
Well Liked
3127 posts
@Deight, That's because you keep using the for loop... For each tag on the page, you print the combined/joined tags.
last edited 08/10/21 by pamtbaau