Last active
August 29, 2015 14:22
-
-
Save primozcigler/678b74c1e0262a1d4cb7 to your computer and use it in GitHub Desktop.
Using Zendesk API for article in multiple sections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// fix to display general questions in themes' sections | |
// using Zendesk API | |
// @link https://developer.zendesk.com/rest_api/docs/help_center/articles#list-articles | |
(function() { | |
if ( $( '.breadcrumbs a[href*="200506781"]' ).length ) { // 200506781 is ID of the section for general questions | |
var config = { | |
$articleList: $( 'ul.article-list' ), | |
tmpl: _.template( '<li><a href="<%= url %>"><%- title %></a></li>' ), | |
apiUrl: 'https://proteusthemes.zendesk.com/api/v2/help_center/sections/200132421/articles.json', | |
}; | |
var appendArticles = function( data ) { | |
_.each( data.articles, addArticle ); | |
}; | |
var addArticle = function( article ) { | |
config.$articleList.append( config.tmpl( { | |
title: article.title, | |
url: article.html_url, | |
} ) ); | |
}; | |
$.get( config.apiUrl, '', appendArticles ); | |
} | |
})(); | |
// hide dummyhide articles - if section has 0 articles fix | |
(function() { | |
$( '.article-list a[href*="dummyhide"]' ).parent().remove(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HI Primoz,
Thanks very much for putting this together. Wondering if you might have time for a question? I am getting an "Unexpected token ILLEGAL" error on line 8 when trying to implement it with my Zendesk instance. Any ideas what the issue could be?
Thanks,
Starr