巧妙地将字符串和变量连接为修饰符的参数


Smarty concatenate string and variable as parameter for a modifier

在Smarty 3中,如何在修饰符的参数内连接多个字符串和变量?

{$message|modifier:'something':'bla'$foo'bla':'hello'} //gives the error: Unexpected "$", expected one of: "}"
{$message|modifier:'something':'bla'.$foo.'bla':'hello'} //gives the error: Unexpected ".", expected one of: "}"
{$message|modifier:'something':'bla'`$foo`'bla':'hello'} //gives the error: Unexpected "`", expected one of: "}"
{$message|modifier:'something':'bla'{$foo}'bla':'hello'} //gives the error: Unexpected "{", expected one of: "}"
{$message|modifier:'something':'bla{$foo}bla':'hello'} //the parameter evaluates to "bla{$foo}bla"

使用cat修饰符也不起作用,因为您不能在另一个修饰符的参数中使用它

我发现了如何使用cat:

{$message|modifier:'something':{'bla'|cat:$foo|cat:'bla'}:'hello'}