我正在使用Twig和Handlebars.js,但是遇到了冲突。我找到了两种解决方案。这两种方法哪一种被认为更合适?或者有没有第三种更合适的方法?如果使用我的Option 1,是否有任何建议的命名标准来将handlebars模板与twig模板关联?
Option 1使用Twig源代码
my_twig_template1.html
{% block content %}
<h1>Hello</h1>
<p>{{ someTwigPhpVar }}</p>
{{ source('my_handlebars_template1.html') }}
{% endblock %}
my_handlebars_template1.html
<script id="my-handlebars-item-1" type="text/x-handlebars-template">
{{someHandleBarVariable}}
</script>
<script id="my-handlebars-item-2" type="text/x-handlebars-template">
{{someHandleBarVariable}}
</script>
选项2:使用Twig verbatim
my_twig_template2.html
{% block content %}
<h1>Hello</h1>
<p>{{ someTwigPhpVar }}</p>
{% verbatim %}
<script id="my-handlebars-item-1" type="text/x-handlebars-template"></script>
<script id="my-handlebars-item-2" type="text/x-handlebars-template"></script>
{% endverbatim %}
{% endblock %}