How not to parse some parts of templates


#1

Hi, I am trying to implement search with algolia and I would like to render allItems template based on script inserted in the html.

Hugo fails to compile my template, as it tries to interpret it as hugo template (usage of {{#hits}).

This is inside my partial/search.html

<script type="text/html" id="hits-template">
  <table class="table table-striped table-condensed">
    <thead>
      <tr><th>name</th><th>brand</th><th>price</th></tr>
    </thead>
    <tbody>
    {{#hits}}
      <tr><td><a href="#hit-{{objectID}}">{{section}}</a></td><td>{{title}}</td><td>{{url}}</td></tr>
    {{/hits}}
    </tbody>
  </table>
</script>

This is my JS

search.addWidget(
    instantsearch.widgets.hits({
      container: '#hits',
      templates: {
          empty: 'No results',
          allItems: document.getElementById('hits-template').innerHTML  // <-- importing the template which is written in mustache 

        }
    })

It there a way to tell Hugo to not parse some parts of temple?


#2

Pass certain parts through a function like safeHTML. There are a lot of functions, so read through them and search the forums for similar questions, there are a lot of examples.