Access article's parent category

18 Comments

  • Jessie Schutz
    Comment actions Permalink

    Hi Patrick!

    That information should show up in the breadcrumbs at the top of the article. Are you not seeing those in your theme?

    0
  • Patrick Caughey
    Comment actions Permalink

    Hi Jessie,

    Thanks for your response! Yes, that information does appear in the breadcrumb trail.  What I'd like to accomplish though is to set the page title (on article pages) as the article's category name.

    If {breadcrumbs} accepted a parameter for individual path objects, i.e., {breadcrumb.0} or {breadcrumb 0}, it'd be easy.  Or, if the category object was accessible on the article page, this could be accomplished the same way {section.name} can be used.

    I see from the documentation that currently this not possible.  My hope is that there is a workaround (maybe using javascript?).  I'm new to zendesk development, any suggestions are much appreciated :D.

    0
  • Jessie Schutz
    Comment actions Permalink

    Hey Patrick,

    It miiiiight be possible, but that's outside the purview of Support, I'm afraid.

    We have a number of civilian Help Center experts running around here, though, so I'm hoping that one of them will be able to shed some light on the subject!

    0
  • Diziana
    Comment actions Permalink

    Hi Patrick,

    You can do this:

    • Go to article template and add class ‘article-title’ on element where you want to list article-title. For example: <h1 class=“article-title"></h1>.

    • Now go to js and add the below code -
    var _articleTitle = $('ol.breadcrumbs > li:nth-child(2) > a')
    .html();
    $('.article-title').html(_articleTitle);
    • Save and publish changes

    I hope this would work.

    Let me know if you face any problem.

    Cheers,

    Diziana

    0
  • Patrick J. Caughey
    Comment actions Permalink

    Hi Diziana,

    Thank you! Works perfectly.

     

    - Patrick

    0
  • Ryan Burney
    Comment actions Permalink

    I have the same question. Slack's help center shows the category name and description on each article page; for example:

    https://get.slack.help/hc/en-us/articles/204092246-Editing-your-profile

    "Using Slack" is the category name, and the text below that is the category description. According to the docs, and everything I've tried, there appears to be no way to get this. While the jQuery trick offered above by Diziana works for the title, there is no way to get the category description since it is nowhere on the page.

    I've tried using: {{../category.name}} and changing context using {{#with article}} but I either get a syntax error, or nothing renders.

    Surely there is a way to get this information on the article page, since Slack is doing it!

    0
  • Jessie Schutz
    Comment actions Permalink

    Hey Ryan!

    If you inspect the page you'll see that they have a banner section class, which I believe they would have coded up in the CSS, and then just used regular HTML to add the Category name and description.

    I know just enough about this stuff to be dangerous, so I can't give you any more detail than that, but I'll see if one of the Mods is available to weigh in on it.

    0
  • Annabethcarroll
    Comment actions Permalink

    For my article pages, I used the {{breadcrumbs}} token. I then used CSS to hide everything in the breadcrumbs EXCEPT the category name. 

    The hierarchy of pages in the breadcrumbs for an article is section name > category name > article name. With CSS, you can show only the middle item, the category name. It will look something like this: 

    .breadcrumbs li:last-child,
    .breadcrumbs li:first-child {
         display: none;
    }

    Of course, you'll probably want to wrap this section with another class so that you can make your CSS more specific, otherwise your actual breadcrumbs won't show up properly -- only the middle items would appear.

    Hope this helped!

    0
  • Jessie Schutz
    Comment actions Permalink

    Thanks for sharing, Annabeth!

    0
  • MiiiA Pty Ltd
    Comment actions Permalink

    Thanks Diziana & Annabeth, & all!!

     

    I have used a combination of these techniques to achieve the Category Name and a Description on both the Category and Article pages. Really nice work.

     

    Dan

    1
  • Remi Barraquand
    Comment actions Permalink

    Hi all,

    it would be really great Jessie if the category information could be accessed from the section object. Indeed the "article page" provide an access to "section" (see https://developer.zendesk.com/apps/docs/help-center-templates/article_page) however the section object does not expose the "category" (see https://developer.zendesk.com/apps/docs/help-center-templates/objects#section-object) which is weird to me.

    Doing so will make our life easier. Do you think you can request such feature to the PM/Engineers?

    Thanks a lot for your support on this.

    0
  • Nicole - Community Manager
    Comment actions Permalink

    Hey Remi - 

    The best way to share feedback to our Product team is to post in the Product Feedback forum. They aren't able to respond to everything there, but they do read it. 

    0
  • Remi Barraquand
    Comment actions Permalink

    done

    0
  • Nicole - Community Manager
    Comment actions Permalink

    thank you!

    0
  • Joachim Shotter
    Comment actions Permalink

    Did anything get done about this. Its pretty poor you cant access category ID's from page with in the chosen category. 

    Thanks

    0
  • Jessie Schutz
    Comment actions Permalink

    Hi Joachim!

    This functionality hasn't changed; I'd recommend checking out the solutions provided by other Community members above!

    0
  • Nicolas Abdelnour
    Comment actions Permalink

    Hey!

    Just like Remi, I need the category information from a section object. Injecting a script that adds HTML to the tag would not work, as I'm looking to use the category ID to add a different icon (very similar to what is available in the category page). Is there any way I can access a section's category? The solutions above are not exactly what I'm looking for.

    Thanks again

    0
  • Devan La Spisa
    Comment actions Permalink

    Hello Nicolas,

    As the platform stand, your request stands outside of its current parameters and capabilities. I would recommend posting in our Product Feedback forum so our developers could consider your suggestion for future updates.

    Product Feedback Forum

    0

Please sign in to leave a comment.

Powered by Zendesk