CMS Development

ezraassj
参加者

Excluding specific tags from tag lists that is being displayed

Hello,

On my blog listing page. I have 3 blocks for the 3 most recent articles.

On each of those blocks are displayed the tags from each article.

In each of those tags list there is a tag corresponding to the status of the article (New article, Editor's pick) and depending of this choice it is displaying a small label on the article itself.

 

However to avoid repeating the tags that are indicated in the labels, I would like to hide them.

 

So to do that I wrote the following code which is working like I want

 

<div class="tags">
  {% set taglist = recentposts[0].tag_list %}
  {% for tags in taglist %}
    {% if !(tags == "Editor's_pick" || tags == "New_Article") %}
{% set tags = tags|join(", ") %}
{% set tags = tags|replace("_"," ") %} {{ tags }} {% endif %} {% endfor %} </div>

 

 

The only issue I have with this is that I would need to add a coma after each tag except if there is only one tag showing up and except on the last tag appearing.

 

How should I proceed, is there an easier solution ? (I though about using the |join filter but doesn't seem to work)

 

By the way I dont get why I can't save my code if I remove the {% set tags = tags|join(", ") %} so that's why I let it.

0 いいね!
3件の返信
Kevin-C
名誉エキスパート | Solutions Partner
名誉エキスパート | Solutions Partner

Excluding specific tags from tag lists that is being displayed

Hey @ezraassj 

 

What is displayed when you print the tag_list variable?

 

{% set taglist = recentposts[0].tag_list %}

{{ tag_list }}
Kevin Cornett - Sr. Solutions Architect @ BridgeRev
ezraassj
参加者

Excluding specific tags from tag lists that is being displayed

Hey @Kevin-C 

I still didn't find a solution at this day. In case you pass by on the topic again, i'm still open for a solution 😄

0 いいね!
ezraassj
参加者

Excluding specific tags from tag lists that is being displayed

Hey @Kevin-C 

 

I guess you meant taglist instead of tag_list.

 

When I print the taglist variable it is showing all the different tags I added for this post when creating the post so for example [New_Article, Editor's pick, Lifestyle]

0 いいね!