Created
November 27, 2017 15:22
-
-
Save rayrutjes/db096707679830cda704ed8a484f47cb to your computer and use it in GitHub Desktop.
Zendesk <> Algolia plugin for WordPress autocomplete integration
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
<!-- ... --> | |
<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