Php Algolia Instantsearch与细枝模板-can';t分裂字符串
我正在使用OctoberCMS并从Algolia返回值,细枝模板似乎无法使用Php Algolia Instantsearch与细枝模板-can';t分裂字符串,php,twig,octobercms,algolia,Php,Twig,Octobercms,Algolia,我正在使用OctoberCMS并从Algolia返回值,细枝模板似乎无法使用split()过滤器拆分 我在每个搜索项中都存储了这样的颜色 ["Blue_#3498db","Dark Green_#16a085","Turquoise_#06e5c7"] 根据Algolia Instantsearch文档,我的模板如下: <script type="text/html" id="refinementListColourItem-template"> {% set itemVa
split()
过滤器拆分
我在每个搜索项中都存储了这样的颜色
["Blue_#3498db","Dark Green_#16a085","Turquoise_#06e5c7"]
根据Algolia Instantsearch文档,我的模板如下:
<script type="text/html" id="refinementListColourItem-template">
{% set itemValue = '{{value}}' %}
<div>
<a href="#">
<span>
{% set tests = itemValue|split('_') %}
{% for test in tests %}
{{ test }}
{% endfor %}
</span>
</a>
</div>
</script>
如果我
dump()
变量itemValue
返回为字符串,并且未转换为HTML特殊字符,我认为您可能对Algolia Instasearch的解释有误。Instasearch是一个Javascript API,因此下面的代码(如@DarkBee在注释中提到的)将拆分字符串值“{{value}}”
。问题中的细枝模板将返回以下HTML
<script type="text/html" id="refinementListColourItem-template">
<div>
<a href="#">
<span>
{{value}}
</span>
</a>
</div>
</script>
另外,对模板进行以下更改:
<script type="text/html" id="refinementListColourItem-template">
<div>
<a href="#">
<span class="color">
{{value}}
</span>
</a>
</div>
</script>
你能分享你如何设置{{{value}}
的详细信息吗?这样我们就可以在本地系统中重现{%set itemValue={{{value}}{}
-我不确定你在这里期望发生什么,但通过这个语句,你实际上将文本{value}}
存储在itemValue
中,一个字符串,它不包含任何。
,因此您的代码按预期工作。。。
//assuming your algolia javascript variable is called search, and you have jQuery included on the page (common for OctoberCMS)
search.on('render', function() {
$(".color").each(function(){
var colour = $(this).text().split("_")[0];
$(this).text(colour); //will output first part of the text value
});
});
search.start();
<script type="text/html" id="refinementListColourItem-template">
<div>
<a href="#">
<span class="color">
{{value}}
</span>
</a>
</div>
</script>