Smarty模板添加变量出错


Smarty template add to a variable error

我正在尝试

    {$mouseOver = "test"}
    {$mouseOver .= " continue"}

就像我可以在简单的php:

$test = "Hello";
$test .= " continue";
echo $test; // will output: Hello continue

在Smarty PHP模板中。我怎样才能做对呢?

v2p在正确的轨道上,但具体来说,您可以这样做:

{assign var="varname" value="Hello"}
{assign var="varname" value="{$varname} World"}
{$varname}

这将打印"Hello World",并且$varname将继续保持该值,直到进一步修改。

尝试{assign var='name' value='some value'}

看到http://www.smarty.net/docsv2/en/language.custom.functions.tpl language.function.assign


关于字符串连接,使用cat修饰符

见http://www.smarty.net/docsv2/en/language.modifier.cat