我目前正在使用Algolia + Hogan模板。但我經常遇到以下錯誤,我在CraftCMS上運行Algolia。Hogan使用Algolia模板
<script>
var hitTemplate = Hogan.compile($('#hit-template').text());
const search = instantsearch({
appId: '{{ craft.searchPlus.getAlgoliaApplicationId }}',
apiKey: '{{ craft.searchPlus.getAlgoliaSearchApiKey }}',
indexName: 'products',
urlSync: true
});
search.addWidget(
instantsearch.widgets.hits({
container: '#hits',
templates: {
empty: 'No results',
item: hitTemplate
},
hitsPerPage: 6
})
);
search.start();
</script>
這是我的模板。原始的,因爲CraftCMS拋出了錯誤。
{% raw %}
<script type="text/template" id="hit-template">
{{#hits}}
<li>
<h4><a href="{{ absoluteUri }}">{{ title }}</a></h4>
{{{ description }}}
<p>{{#productImage}}</p>
<img src="{{ url }}"/>
{{/productImage}}
</li>
{{/hits}}
</script>
{% endraw %}
通過控制檯獲取以下錯誤。
Warning: Failed prop type: Invalid prop
templates.item
supplied tot
.Template.js:117 Uncaught Error: Template must be 'string' or 'function', was 'object' (key: item)
感謝您的回答 - 不幸的是,現在我收到以下信息: **未捕獲的TypeError:無法讀取屬性'textContent'null ** – user3082823
通過移動腳本在模板下方移除錯誤 - 但沒有命中模板呈現。 – user3082823
也沒有控制檯錯誤返回:( – user3082823