我正在传递一个字符串给login_create_account_label
,它是:
Not a member? %sCreate a Free account%s.
还有值为
的login_create_account_url
http://localhost/register/
由于第一个格式变量具有HTML,我也在此元素中传递了raw
选项。
<p class="highlight">
{{ login_create_account_label | format('<a href="{{ login_create_account_url }}">', '</a>') | raw }}
</p>
我一直无法让它输出我想要的。
期望(源HTML):
<p class="highlight">
Not a member? <a href="http://localhost/register/">Create a Free account</a>.
</p>
我得到了什么:
<p class="highlight">
Not a member? 0Create a FREE account</a>.
</p>
小枝字符串操作可能有点棘手,因为有一堆工具可用。
不使用输出({{…}})语法,考虑使用'~'操作符将操作数转换为字符串。你可以在这里了解更多。
http://twig.sensiolabs.org/doc/templates.html其他运营商
<p class="highlight">
{{ login_create_account_label|format('<a href="' ~ login_create_account_url ~ '">', '</a>')|raw }}
</p>