Smarty 条件字符串
Smarty Conditionals strings
我需要在 SMARTY 中从两个字符串创建一个字符串,如下所示
{$value.b64id} = ?type=1&id=aWQ9
这是我到目前为止所得到的,似乎无法得到任何地方。我觉得引号把我搞砸了!!
{assign var='controls' value='<a style="color: red;" href="http://example.com'|cat:{$value.b64id}|cat:'">click Me</a>'}
所以我想要的是它的结尾
{$controls} = <a style="color: red;" href="http://example.com?type=1&id=aWQ9">click Me</a>
非常感谢
首先,如果要在模板中显示变量,只需为变量使用分隔符即可。当你在 smarty 函数中使用不必要的变量时,所以
|cat:{$value.b64id}
应该是
|cat:$value.b64id
但是,如果您需要编写一个字符串以便多次重复使用,最好使用 {capture}
{capture "controls"}
<a style="color: red;" href="http://example.com{$value.b64id}">click Me</a>
{/capture}
然后只需使用{$controls}
我需要在 SMARTY 中从两个字符串创建一个字符串,如下所示
{$value.b64id} = ?type=1&id=aWQ9
这是我到目前为止所得到的,似乎无法得到任何地方。我觉得引号把我搞砸了!!
{assign var='controls' value='<a style="color: red;" href="http://example.com'|cat:{$value.b64id}|cat:'">click Me</a>'}
所以我想要的是它的结尾
{$controls} = <a style="color: red;" href="http://example.com?type=1&id=aWQ9">click Me</a>
非常感谢
首先,如果要在模板中显示变量,只需为变量使用分隔符即可。当你在 smarty 函数中使用不必要的变量时,所以
|cat:{$value.b64id}
应该是
|cat:$value.b64id
但是,如果您需要编写一个字符串以便多次重复使用,最好使用 {capture}
{capture "controls"}
<a style="color: red;" href="http://example.com{$value.b64id}">click Me</a>
{/capture}
然后只需使用{$controls}