我有一个 html 模板,其中包含一些 handlebarsjs 代码,我将这些代码包含在我的页面中以呈现一些产品弹出窗口。问题是这些模板有点复杂,我也需要翻译它们上的标签,有没有办法将异常通知给树枝解析器?这样,即使代码在raw
块内,它还是会被渲染?显然,如果我使用翻译标签,它就不起作用{{ 'translations.project.template.price'|trans }}
例如:
index.html.twig:
{{ include('WebBundle:Frontend:partials/templates/product-template.html.twig') }}
product-template.html.twig:
{% trans_default_domain "home" %}
{% raw %}
{{#if isLovePromo}}
<div class="product-infotag promo">
Promozione <!-- HERE is the text i'd like to translate -->
</div>
{{/if}}
{% endraw %}
目前我正在通过将翻译传递给车把呈现的对象来解决它,所以我有这样的东西:
index.html.twig:
data.translations = {
promo: "{{ 'translations.project.template.promotion'|trans }}"
}
模板.渲染(数据);
product-template.html.twig:
...
<div class="product-infotag promo">
{{ promo }}
</div>
...
这种方法有效,但它显然是矫枉过正,我有模板,我必须在其中传递超过 12 个字符串,这样看起来对我来说效率不高。
有没有办法直接在树枝中解决这个问题?