javascript - Use a hogan template in instantsearch.js widget -
i'm trying implement algolias instansearch.js. search results going have lot of html i'd extract hogan template. results appear loading nothing being rendered?
<script type="text/template" id="hit-template"> {{#hits}} <div class="hit"> <div class="hit-image"> <p>test: {{ objectid }}</p> </div> </div> {{/hits}} </script> <script> var hittemplate = hogan.compile($('#hit-template').text()); search.addwidget( instantsearch.widgets.hits({ container: '#hits-container', templates: { empty: 'no results', item: function(data){ return hittemplate.render(data); } }, hitsperpage: 6 }) ); </script>
any appreciated
you not need use hogan yourself, give template:
var hittemplate = document.queryselector('#hit-template').innerhtml;
search.addwidget( instantsearch.widgets.hits({ container: '#hits-container', templates: { empty: 'no results', item: hittemplate }, hitsperpage: 6 ) );
also check console error messages. thanks
Comments
Post a Comment