Recent searches
No recent searches
Show Icon Based on a Label
Answered
Posted Jun 17, 2021
I want to display a video icon next to article links for articles that contain embedded videos. So, for each article that has an embedded video, I created a label "video".
Is there a way to have an if/else query for labels in the Category/Section pages that display article links? For example:
<a href="{{url}}" class="section-base__link">{{title}}</a> <IF LABEL ="video" THEN><img src="{{asset 'video32x32.png'}}" width="16" height="16"> <ELSE NOTHING>
I obviously don't know how to write If/Else queries, but I hope my explanation is clear. Any help would be appreciated.
1
6
6 comments
Bruce Michelsen
The section_page.hbs file does something similar to what you're asking when creating links to Promoted or Internal articles.
See how this is done for promoted to understand what you can then do with video labels.
Go to this area in the section_page.hbs file:
Notice that the logic is using template helpers and objects to process the articles (#each section.articles), conditionally (#if promoted) adding a class, text, and icon when writing the article links. For more information about template helpers and objects, see https://developer.zendesk.com/documentation/help_center/help-center-templates/introduction/
You could pattern after either the promoted or the internal example. Let's look at promoted.
This logic checks to see whether the article is promoted. If so, then it adds a title using dynamic text and a class for the star icon, which is defined in the CSS:
To make this work for your scenario of adding an icon if the article has a "video" label:
This logic reads the labels in the article being processed, checks for a "video" label, then adds the text and icon (same as used for Promoted). For your situation, you can use dynamic text or not, and set your own icon class, then, in the style.css file, map your icon.
For example, you could change the class from icon-star to icon-video
<span class="icon-video"></span>, then in the CSS add
0
Oren Ben Ami
Hi Bruce,
Thanks for the detailed explanation. I gave a label "video" to one of my articles, and then I added your code. However, I got the following in the section_page.hbs file:
0
Bruce Michelsen
Oren, if you can, show what you have now in the section.articles area of the code.
0
Oren Ben Ami
<!-- Links to Existing FAQ Articles -->
<div class="container section-page">
<div class="container-inner">
{{#if section.articles}}
<ul class="article-list">
{{#is section.id 111111111}}
<li class="article-list-item"><a href="'">This is a customized link</a></li>
{{/is}}
{{#each section.articles}}
<li
class="article-list-item {{#if promoted}}article-list-item--is-promoted{{/if}}">
{{#if promoted}}
<span class="fas fa-star" title="{{t 'promoted'}}"></span>
{{/if}}
<a class="article-list-item__link" href="{{url}}">{{title}}</a>
</li>
{{/each}}
</ul>
{{else}}
<p><i><a href="{{section.url}}">{{t 'empty'}}</a></i></p>
{{/if}}
{{pagination}}
</div>
</div>
0
Bruce Michelsen
Is there a mapping for icon-star in the CSS? If not, you could map the icon inside the span tag within the #is identifier 'video' statement.
Here's your code segment with the labels statement (after #if promoted):
<!-- Links to Existing FAQ Articles -->
<div class="container section-page">
<div class="container-inner">
{{#if section.articles}}
<ul class="article-list">
{{#is section.id 111111111}}
<li class="article-list-item"><a href="'">This is a customized link</a></li>
{{/is}}
{{#each section.articles}}
<li class="article-list-item {{#if promoted}}article-list-item--is-promoted{{/if}}">
{{#if promoted}}
<span class="fas fa-star" title="{{t 'promoted'}}"></span>
{{/if}}
{{#if labels}}
{{#each labels}}
{{#is identifier 'video'}}
<span data-title="{{t 'promoted'}}" class="icon-star"></span>
{{/is}}
{{/each}}
{{/if}}
<a class="article-list-item__link" href="{{url}}">{{title}}</a>
</li>
{{/each}}
</ul>
{{else}}
<p><i><a href="{{section.url}}">{{t 'empty'}}</a></i></p>
{{/if}}
{{pagination}}
</div>
</div>
0
Oren Ben Ami
@... I appreciate all your help! I will give it a try...
0