With the addition of our Help Center templating language Curlybars, the ability to add conditional statements was exposed which allows for dynamically impacting the rendering of your Help Center pages. By using conditional statements, we can target the unique id number of a category, section, article, topic, or post and hide that item while displaying others.
If you need to find the id of the item you would like to hide, just navigate to the page for that item and look to the URL. You should find something like /hc/en-us/categories/200420805-General
. The 200420805
is the id of my category.
Here's a little animation to highlight what I'm trying to achieve when I hide a category on the home page of the Help Center (watch 'Category 1'):
The code
I will cover a few scenarios here to elaborate on how these can be used. In these examples, I will be using the default code found in the Copenhagen Help Center theme. I will primarily be using the isnt helper, as the basic idea with it is that if the value does not match, then render the displayed code - effectively hiding (or not rendering) the identified item. You can see here I want to exclude a specific category on the home page, so I've passed it through the isnt
statement:
I have attached the entire code of my homepage template from this example here. You can change my category id for your own, and then you will be able to hide your categories.
Hiding multiple items
Hiding multiple items adds a couple more lines of code as we cannot pass multiple id numbers into a single conditional statement. Instead, we will want to nest the conditional statements so they can be analyzed appropriately. Here's an example:
If you would like to download the code for hiding multiple categories, you can find that code here.
Another example with articles
I know I've been talking about categories quite a bit, so I wanted to show how to implement this in another space. My scenario is I want to reduce the exposure of a certain article, but make it accessible via Search or a direct link to my customers. I've chosen the article page in the Copenhagen theme where other articles in the same section as the current article appear in a sidebar like this:
You may have hidden your article already at the section level, but we also will want to target the article here:
And again, here is the code if you would like to try it in your article template.
Some tech notes about this functionality
You may have noticed a pattern here that the code was being implemented in the {{#each}}
helper which iterates through the array of the specific items being requested. The each helper is native to handlebars.js, and you can read more on it in their documentation here. In the last image above, you can see the {{#each section.articles}}
in the code which renders the articles for the current section, but when the article is encountered with the id 219527708
, that code is instead skipped and the rendering moves onto the next article.
There may be some other ways to achieve a similar behavior, so feel free to try your hand at some other conditional helpers, but this should be a good start.
46 Comments
Can this be used to hide specific file types in attachments?
We are publishing a lot of DITA image files into KB and they are mostly all .png files.
These end up as a huge list at the bottom of an article, which we don't want to see or need.
We just want to block .png's. All of the other attachments we post are PDF's, Word, Excel, type files.
Thanks.
BobbyG66
Hi Bob Garber, you can check (with if condition) the file type using JS and then hide this (png files only)
Thanks.
Thanks Ifra,
I wrote this code, but it is hiding all file types. Not sure if I have something in the wrong order, or if the code is wrong.
Hi Bob Garber,
Add the code at the bottom of your script.js file:
Make sure document_head.hbs file must have jQuery CDN:
Vlad
Thank you for your advice the other day. https://support.zendesk.com/hc/en-us/articles/4408845769882/comments/4483557247642
The way you taught me helped me achieve what I wanted to do!!
Thanks Ifra!!!
That code worked perfectly! I owe you a coffee!
Bob
Ifra Saqlain is it possible to hide certain elements of the page based on a URL parameter?
We would like to hide the header (as well as other elements) when the support page is visited from the web view from an app.
Hi Maximilian Kreisler, yes you can hide using JS or CSS.
Add CSS at top of the homepage like below. I add this code at home_page.hbs because I'm hiding it only for homepage not other pages.
-
HI, is there a way to hide articles from Search Results and/or Section page by labels or content tags. Essentially, if an article has the content tag 'abcdef', don't show it in the Search results? Thanks in advance!
- as far as I know, this is not supported by ZD, so it's not doable.
Jake Bantz
We are going to do a Beta test of a product. We want to link to articles in our help center, but don't want those showing up in a list or category, however. we DO want the direct link the the article show up.
For example:
Let's say we have an iOS app for our product and we need to Beta test it. We have links in the iOS app that lead to how to use the app, but since the app is not available for use yet, we want to hide the articles, but have those testing to be able to see the articles (without having a Zendesk account).
Is this possible?
Lisa Sedlak we did something similar in our public help center. We hid specific articles from displaying in Category, Section and Article sidebar navigation cribbing Jake's code from his article_hide_in_sidebar.txt attachment. Basically as he says you follow the convention of adding the isn't helper after the #each helper for articles in conjunction with the article id i.e. {{#isnt id 1234}}
For more than one article you add multiple {{isnt}} and close each with {{/isnt}}. I wanted/preferred to use labels instead of individual article ids but wasn't able to get that working.
Here's what our category_page.hbs code snippet looked like as an example (I just added the stuff surrounded by comments.
Lisa Sedlak, Lila is right on with their suggestion.
There is a limitation that using these workarounds, it is not possible to hide the article from search (this is discussed a little earlier in the comments on this article). A possible workaround would be to instead use a custom page for the 'hidden' documentation, and provide those Beta users with the destination of that page.
Hope that helps.
I’m using Zenplates’ Ruby theme and want to selectively hide about 12 articles from a category page and some of its sections.
I’m still trying to figure out where to put the {{isnt id… codes for the theme templates, but my question is whether I need to include any html elements between the opening and closing {{/isnt}} since the intention is that those list items do not render.
Ari the isn't helpers surround the code block that lists articles. So essentially it's saying list the articles which are not the article id specified in the helpers. You shouldn't need additional html.
As far as location, you put the isn't helpers after the each articles helper on the category, section and article templates (see my comment above for full code snippet I used):
NOTE: I hid articles in ALL categories/sections/articles which is a bit different than what you want to do...but I would think you could possibly use if/else + the isn't helpers for that.
https://developer.zendesk.com/documentation/help_center/help-center-templates/introduction/#conditional-helpers
Is there a workaround to hide an article from search as well? Ifra Saqlain perhaps you've cracked this?
Please Zendesk, let us publish unlisted articles 🙏🏼
Please sign in to leave a comment.