Help center templating cookbook

Return to top

40 Comments

  • Catherine Michalak

    Hi,

    Is there anyone who could help me add subsections to my custom HC code?

    I am struggling to get the section with subsections to show if it doesn't have an article in it (ie. the subsections have articles but until there's an article in the section itself, it doesn't show on the category page) and struggling to keep the layout the same on the section with subsections level as it is on the category with sections level.

    TIA!

    Catherine

     

    0
  • Emelie Stjernquist

    Hello @...,

    Just so I get it right, you wish to display an "empty" section?

    I'm not sure that that is possible to do (at least I've not manage to do that), however I have a suggested work-around which is to:

    1. Create an Article on the Section you wish to display (one that is OK to find if found via search function)
    2. Create a custom Section-template where you modify the html, remove the part that displays/list the articles - Guide from Zendesk help
    3. Edit the Section and assign the new template and publish the Section and Article

    I usually elaborate, test back and forth in the templates until I get the result I want. You can also preview it in "Preview mode" before publishing it.

     

    I hope this helps you to get closer to what you wish to accomplish, good luck!

    //Emelie

    0
  • Francois Spinnael

    The Current_local.name trick isn't working. 

    I'm using this list: https://support.zendesk.com/hc/en-us/articles/203761906-Zendesk-language-support-by-product

    And for some reason, the rename of the "language" is working for English (World) that is defined as a "Variant" but all the other ones, aren't working (Estonia, Lithuania, Latvia, Luxembourg,...)

    <button class="dropdown-toggle" aria-haspopup="true">
    {{#is current_locale.name 'English (Luxembourg)'}}
    Test
    {{else}}
    {{current_locale.name}}
    0
  • Augusto Silva
    Zendesk Engineering

    Hey @...

    Try something like this instead (language names can change):

    {{#contains current_locale.url "/en-us"}}
    true
    {{else}}
    false
    {{/contains}}
    0
  • blak3r

    My Activities has `{{requests}}` template variable on it.  The Home Page does not.  Is there a simple way to expose the `{{requests}}` to the home page for signed in users?

    I'd like to show them their 5 most recent requests on the homepage so it's more visible.

    If that cannot be done, could a Custom Page do this?  Essentially I want a landing page from our product for support that has both their requests and then knowledge base shown under it.  One stop landing page from my product.  We use SSO so our users are already authenticated when going there from the app.

    1
  • Greg Katechis
    Zendesk Developer Advocacy

    Hi Blake! I thought about this for a bit to see if I could get creative, but there isn't any way that I could envision where this could be accomplished. As you noted, `{{requests}}` don't exist in the home page template and custom pages also do not contain that helper. I wish I had better news and if I think of anything, I'll drop you a line here.

    0
  • blak3r

    Greg-Katechis - thanks for giving it some thought.  I suppose this would need to be accomplished with custom javascript to call an api endpoint we'd host that would then use the REST api and return the data back.  Blockers here: 1) simple documentation showing how to add javascript that invokes web requests to a third party server 2) Any tips on how we could authenticate on our server code that the user account is in fact authenticated... like if we had /api/getTickets?user=<emailAddress> we need to verify the user is in fact logged into zendesk somehow so they couldn't exploit the api to get other peoples tickets. 

    1
  • Greg Katechis
    Zendesk Developer Advocacy

    1) For this, you could just make an AJAX request from the custom code in your help center to initiate this call to your server/middleware. While it isn't the exact scenario that you're looking to accomplish, this article should give the basic framework that you would need and then you can just swap out your URL/endpoint.

    2) This one is giving me all sorts of problems...both from a basic implementation standpoint, but especially from a security standpoint. We don't have any method of using OAuth in Guide, which would be the easiest way to accomplish this. You could also use the signed_in helper to confirm that someone is signed in and then grab the CSRF token to do...something clever? Like I mentioned, I don't feel comfortable with this, but maybe the idea would spark something in someone else to a function solution!

    0
  • blak3r

    Thanks Greg. Appreciate the link and the quick response. Maybe I can get a value that is set by the login to uniquely identify the session or something. I’ll hack around. I could provide a token in the return_to portion of the jwt flow. Then modify every page template to store that token in a cookie. And pass that along with server Ajax calls and of course have that same token stored in the user db for checking against. Or maybe just the primary entry point page and have it only work if they redirected there. I’ll sleep on it.

    1
  • Greg Katechis
    Zendesk Developer Advocacy

    Oh that's a great idea if you use JWT! I wouldn't recommend storing the token in the DB, as that will change on each login, but you could use the shared secret from Zendesk to verify the signature on your server. The JTI might cause a problem, although if you're just storing that as a cookie and not doing any authentication/authorization in the traditional sense, this could work.

    Let me know if you get this working or hit any snags with this. This could be a great tip for other users looking for a similar solution!

    0
  • blak3r

    It appears the jwt token is stored in an object in ```Session Storage.z2_sunco_widget_auth.jwt```

    So, in the requests to our server we could include the users email, jwt, and the JTI.  The server would take the JTI and resign the payload.  If that payload matched the jwt supplied with the request then we could assume that the user was in fact the email provided to the request.

    In terms of how to get the JTI, there are two approaches I see... 
    1. Store the JTI in our user table each time a request is built... Con here is possible synchronization issues. For example, we were planning on having links in our product just include the jwt to avoid any perceived glitchy redirect behavior from enduser standpoint.  For example to go to /hc/article/103 our link would be https://subdomain.zendesk.com/jwt?jwt=<token>&return_to=https://subdomain.zendesk.com/hc/article/103

    2. Pass the JTI as a GET param in the return_to and store that to a cookie with custom Javascript code on each page template.  CON here is long urls look gross and add potential for user to bookmark a link with a JTI in it... Probably could mitigate this by updating the url.  

    3. Get our helpdesk working on a subdomain of our domain.  Use https://support.mydomain.com instead of https://<zdsubdomain>.zendesk.com and have our webapp set a cookie to root domain that the zendesk code could also see. Probably the best option.

    Questions for you... is this z2_sunco_widget_auth a reliable key for the JWT token?  That sunco part is throwing me off.  Also, I'm not a JWT security specialist, I can't see why having the JTI exposed would be that insecure... given you can't sign a payload without the shared secret but maybe i'm missing something.  Feel free to DM me personally if you prefer.

    0
  • Maxim Ageev | null | null

    I need to disable search indexing on the zendesk subdomain. 
    To only allow it on our company domain.
    I would like to add in header template the following line <meta name="robots" content="noindex">
    But only if the domain is helpcenter. Is there a variable in a template that stores the current domain? 
    https://stackoverflow.com/q/71527073/7921383

     

    0
  • Katrina Greeves

    Is it possible to filter search results by label? 

    e.g

    Article 1 is labelled A
    Article 2 is labelled B
    Article 3 is labelled A C

    I'd like to add a sidebar filter for each label. 

    If I select filter A, I will only then see articles 1 and 3.

    0
  • Dave Dyson
    Hi Katrina, 
     
    There isn't currently a way to filter by label, although articles with labels matching the search terms will be featured higher in the search results. If you'd like to suggest this to our product team, please post your use case to our Feedback - Help Center (Guide) topic, using this template. Thanks!
    0
  • Taehyoung Kim

    Hi, I'm trying to add the content tag feature in our customized template (Copenhagen 1.8.1) but facing some problems.

    I have successfully added content tags in our knowledge base article, but still figuring out how to add them to the search result. I'm basically having a look at search_results.hbs of the recent release. But if I add the lines here to my old template, it said that 'content_tag_filters' does not exist. Does the variable name differ from version to version? Is there a way to implement this on Copenhagen 1.8.1?

    Thanks in advance :)

    Taehyoung

    4
  • Beth

    I'm having the same issue as Taehyoung Kim above. Appreciate any help - thank you!

    3
  • Christian de Heij

    Having the same for my template content_tag_filters does not exists. Any help to get it in?

    1
  • Sabine Hanna

    Same here regarding the content_tag_filters. Any help would be appreciated!

    0
  • mfg

    blak3r - were you able to solve for securely getting the requests on a separate/home page without exposing tickets the authenticated user shouldn't have access to?

    We are looking to have something similar (buttons for the forms at the top, [requests | article list] in a flex box beneath. Without that "{{requests}}" helper, the current solution we're considering is an iFrame / EMBED SRC= , and then style with CSS. It works - but it's not as secure as we'd like.

    0
  • Dane
    Zendesk Engineering
    Hi All, 

    The current version of Copenhagen is Theme version 2.19.4. I have tried the content_tag_filters on search_results.hbs and it worked without any issues. Unfortunately, as customization is outside our scope the best option is to use the lates version of the Copenhagen Theme.
     
    0
  • Gorka Cardona-Lauridsen
    Zendesk Product Manager

    Hi All, 

    We are conducting research to improve our Help Center developer experience and would love to talk to any of you that have tried to edit Help Center theme code.

    If you are interested please answer sign up here and answer the 3 survey questions. I will reach out to you to setup a 30 min Zoom call.

    The interview will be a semi-structured interview where we would like to hear you take us through examples of what you have done or tried to do with customizations and your experience with the tools, documentation etc. you used.

    Looking forward to talking to all of you.

    Gorka Cardona-Lauridsen
    Sr. Product Manager, Zendesk Guide 

    0
  • Tomas M. Parra

    Hello! 
    I'm trying to add a snippet of each article's body underneath the articles' title in the category page. 
    This is the code as is: 
    <ul class="article-list">
                    {{#each articles}}
                      <li class="article-list-item{{#if promoted}} article-promoted{{/if}}">
                        {{#if promoted}}
                          <svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" focusable="false" viewBox="0 0 12 12" class="icon-star" title="{{t 'promoted'}}">
                            <path fill="currentColor" d="M2.88 11.73c-.19 0-.39-.06-.55-.18a.938.938 0 01-.37-1.01l.8-3L.35 5.57a.938.938 0 01-.3-1.03c.12-.37.45-.63.85-.65L4 3.73 5.12.83c.14-.37.49-.61.88-.61s.74.24.88.6L8 3.73l3.11.17a.946.946 0 01.55 1.68L9.24 7.53l.8 3a.95.95 0 01-1.43 1.04L6 9.88l-2.61 1.69c-.16.1-.34.16-.51.16z"/>
                          </svg>
                        {{/if}}
                        <a href="{{url}}" class="article-list-link">{{title}}</a>
                        {{#if internal}}
                          <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" focusable="false" viewBox="0 0 16 16" class="icon-lock" title="{{t 'internal'}}">
                            <rect width="12" height="9" x="2" y="7" fill="currentColor" rx="1" ry="1"/>
                            <path fill="none" stroke="currentColor" d="M4.5 7.5V4a3.5 3.5 0 017 0v3.5"/>
                          </svg>
                        {{/if}}
                      </li>
                    {{/each}}
                  </ul>

    What I want is to add {{body}} underneath <a href="{{url}}" class="article-list-link">{{title}}</a> but I can only print the full article's body, which obviously breaks the whole layout. 

    I tried many things like {{body.slice 0 50}} and more, but nothing seems to work. 

    For the records: I am a developer, I have been through Zendesk documentation (Plus forums, stack overflow, your support, etc) and nothing seems to work. 
    Can you give me a hand to achieve this? 

    Thanks!

    1
  • Tomas M. Parra

    By the way, your console says either something like "body.slice cannot be accessed" , or something like "body doesn't accept these parameters". 

    1
  • Ryan Gilomen

    Tomas M. Parra,

    I use {{excerpt body characters=150}} on my section pages to achieve this.

    Hope this helps!
    -Ryan

     

    1
  • Tomas M. Parra

    Hello @Ryan!
    That worked great for me. Thanks so much!

    0
  • Casey Keefe

    Hey Zendesk & Community! I am trying to use current_locale.name on home_page.hbs to change content based on selected language.

    I have been able to use this in both header.hbs and footer.hbs with no problems, but getting the following error when I try to use it on home_page.hbs

    I am trying to avoid using the Dynamic Content feature if at all possible (just haven't had good luck with it). Thanks!

    0
  • Cory Waddingham

    Is there a way to add metadata for a page? For example, on article pages, I want to add a <title> tag to the page header, so that page crawlers will know the title of the article without any trouble. But I can't find a way to add that page tag, either in the article_page.hbs or the document_head.hbs (adding 

    {{#if article.title}}
    <title>{{article.title}}</title>
    {{/if}}

    just results in an error.

    0
  • Tipene Hughes
    Zendesk Developer Advocacy

    Hey, Casey Keefe!

    You can access the help_center object in the home_page.hbs file. The object has the locale property available which should be what you're looking for.

    Feel free to reach out with any questions!

    Tipene

    0
  • Tipene Hughes
    Zendesk Developer Advocacy

    Hi Cory Waddingham,

    The article object is not accessible within the document_head.hbs file. One way you could look at going about this is by using a bit of custom Javascript to append a title to the page. Here’s an example of one way that could work:

    // Create title element 
    const title = document.createElement('title');
    // Get article title element
    const articleTitle = document.querySelector('.article-title');

    // If article title exists, add title to document head
    if(articleTitle) {
      title.innerText = articleTitle.innerText;
    document.getElementsByTagName('head')[0].appendChild(title);
    }

    



I’m not super familiar with how crawlers interact with dynamically added meta data though so that might be something to look in to if you haven’t already.

    Let me know if you have any questions!

    Tipene

    1
  • Casey Keefe

    Thank you Tipene Hughes !

    0

Please sign in to leave a comment.

Powered by Zendesk