Skip to content

Instantly share code, notes, and snippets.

@rayrutjes
Created November 27, 2017 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rayrutjes/db096707679830cda704ed8a484f47cb to your computer and use it in GitHub Desktop.
Save rayrutjes/db096707679830cda704ed8a484f47cb to your computer and use it in GitHub Desktop.
Zendesk <> Algolia plugin for WordPress autocomplete integration
<!-- ... -->
<script type="text/html" id="tmpl-autocomplete-zendesk-suggestion">
<a class="suggestion-link" href="https://algolia-test.zendesk.com/hc/{{ data.locale.locale }}/articles/{{ data.id }}">
<div class="suggestion-post-attributes">
<span class="suggestion-post-title">{{{ data._highlightResult.title.value }}}</span>
<# if ( data._snippetResult['body_safe'] ) { #>
<span class="suggestion-post-content">{{{ data._snippetResult['body_safe'].value }}}</span>
<# } #>
</div>
</a>
</script>
<!-- ... -->
<script>
/* ... */
/* setup default sources */
var sources = [];
var zendeskIndex = algoliasearch('your app ID', 'search only API key').initIndex('index_name');
sources.push({
source: algoliaAutocomplete.sources.hits(zendeskIndex, {
hitsPerPage: 5,
attributesToSnippet: [
'body_safe:10'
]
}),
templates: {
header: function () {
return wp.template('autocomplete-header')({
label: 'Frequently Asked (can be replaced)'
});
},
suggestion: function (hit) {
return wp.template('autocomplete-zendesk-suggestion')(hit);
}
}
});
/* ... */
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment