聪明的分配变量

发布于 2024-10-08 22:57:18 字数 314 浏览 0 评论 0原文

我试图通过这样做在我的 .tpl 中分配一个变量,

{assign var="image" value="images/stores/{$location.storename|regex_replace:"/[' ']/":"-"|lower}.jpg"}

但是我收到了这个错误,

Smarty 错误:[stores/view-store.tpl 第 135 行]:语法错误:无效属性名称:'|lower'

如何停止此错误,但仍将返回信息的大小写改为小写?

I am trying to assing a variable in my .tpl by doing this,

{assign var="image" value="images/stores/{$location.storename|regex_replace:"/[' ']/":"-"|lower}.jpg"}

however I am getting this error,

Smarty error: [in stores/view-store.tpl line 135]: syntax error: invalid attribute name: '|lower'

How Can i stop this error but still drop the casing of the returned info to lowercase?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

世界如花海般美丽 2024-10-15 22:57:18

即使你降价了,你仍然会遇到问题。 {} 块内不能包含 {} 块。也不能将“”嵌套在“”中。

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

查看该页面,查看复杂的示例。您将使用类似的内容

{assign var="image" value=``}

这可能对您也有用:

http:// /www.smarty.net/docs/en/language.function.eval.tpl

但最终,您应该在 PHP 端执行此操作,逻辑和代码并不意味着位于模板中,除非确实存在没有其他选择。

Even if you take lower off you're still going to have problems. You can't have a {} block inside a {} block. Nor can you have "" nested in "".

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

Look at that page, check out the complex example. You'll use something like

{assign var="image" value=``}

This might also be useful for you:

http://www.smarty.net/docs/en/language.function.eval.tpl

Ultimately though, you should be doing that on the PHP side, logic and code is not meant to be in the template unless there really is no other choice.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文