我目前正在将 smarty 与 zend 框架一起使用,并且我已经设置 smarty 以通过以下方式使用 gettext:
{gettext text="resource-identifier"}
这可以正常工作,但是在尝试将其与 smarty 默认变量处理程序一起使用时遇到了问题。我想做这个:
{$somevar|default:gettext text="resource-identifier"}
但这只会打印“gettext”。关于如何做到这一点的任何建议。甚至可能吗?
我目前正在将 smarty 与 zend 框架一起使用,并且我已经设置 smarty 以通过以下方式使用 gettext:
{gettext text="resource-identifier"}
这可以正常工作,但是在尝试将其与 smarty 默认变量处理程序一起使用时遇到了问题。我想做这个:
{$somevar|default:gettext text="resource-identifier"}
但这只会打印“gettext”。关于如何做到这一点的任何建议。甚至可能吗?
对于 smarty 来说,像这样链接函数的结果是不可能的。您需要查看 gettext 是否可以将其结果分配给变量(assign=varname 参数),或者自己编写(此时只需编写一个新的修饰符,例如 default_gettext:'resource-id')
在假设的分配中,它看起来像:
{gettext text="resource-id" assign="myvar"}
{$somevar|default:$myvar}
在新的修饰符中,它看起来像:
{$somevar|default_gettext:"resource-id"}