问题标签 [smarty3]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
419 浏览

php - Smarty 变量,将 javascript 函数分配为值不起作用(从 v2 升级到 v3)

我有以下代码,适用于 smarty 2.x

但 smarty v3 抛出错误:

我怎样才能解决这个问题?

谢谢!

0 投票
3 回答
4847 浏览

php - smarty中的动态数组键

我只想知道如何访问 SMARTY 中通过 smarty 生成索引的数组。我想稍后访问它。

得到这样的东西:

我喜欢访问$smarty.get.(dynamic generated index)

尝试了几种变体,但没有任何运气。

0 投票
2 回答
2271 浏览

php - Using Smarty 3, Code Igniter 2, and HMVC together with smarty's inheritance?

I am using Code Igniter, The HMVC library, and Smarty with this library.

Smarty is working fine by default, however if I try to use smarty's inheritance feature ( {extends file="master.tpl"}) then we run into an issue.

The extends feature does not look in the module views folder for the extended file (in the above's case master.tpl), instead it only looks in the application/views/ folder and throws an error if it cannot find it.

I could add APPPATH."modules/smartytest/views" to the $config['template_directory'] array in the smarty config file. but that throws an error for each item in the array it checks first for the file. filemtime(): stat failed for application/views/master.tpl

and that has the added issue of, if I have three modules all the the array and the modules all have a master.tpl then no matter what module I call the extend from it will load the first one found.

So, is there a way to get smarty's extend function to behave nicely with the HMVC modules?

0 投票
2 回答
1616 浏览

smarty - 缩短 smarty if 语句

我有一个聪明的 if 语句如下:

我必须在模板中多次比较相同的语句。多次重复这个陈述真的很乏味。我知道我可以缓存一个语句并多次重用它,但我正在寻找是否有可能做这样的事情:

就像在 PHP 中一样,我们可以这样做:

请注意,我无法访问模板的 php 代码,因此只能使用 smarty。任何建议将不胜感激。

干杯。

0 投票
1 回答
118 浏览

smarty - 没有文件属性的 Smarty {include} 安全吗?

例如,{include 'path/to/template.tpl'}

所述格式的文档中没有提及,但它似乎与以下内容相同:

这是一个怪癖,还是设计使然?当我不传递其他变量时,我更喜欢更简洁的语法,但想确保它是一种可接受的格式(版本 3.0.7)。

0 投票
1 回答
1123 浏览

php - Smarty Postfilters / Prefilters 如何在输出前应用于模板

我对如何在 smarty 中使用 post/pre 过滤器感到很困惑。

我需要做的是在页面显示之前搜索和替换页面中的某些元素。我宁愿在调用 $smarty->display 之前执行此操作。这意味着,在它被保存到磁盘之前,但在它被编译之后(所以,后过滤器)。

示例后过滤函数:

如何在 smarty 输出之前应用它。在查看 Smarty 文档(http://www.smarty.net/docsv2/de/advanced.features.postfilters.tpl)和其他一些示例后,我已经尝试过,但似乎没有一个有效。

有人可以给我一个示例代码,说明如何执行此操作,以及如何将参数传递给过滤器($search,$replace)。

谢谢

0 投票
1 回答
1276 浏览

smarty - 如何让 Smarty 自动转义所有模板变量但忽略捕获

我想自动转义所有模板变量,即我希望它们被转义而不必一直写|escape。因此我启用了该$escape_html选项。

然而,显然 Smarty 处理使用{capture}相同方式创建的变量,即使这些可以被视为可信输入。我们的代码库中有很多这样的代码,nofilter到处都写几乎和写一样烦人|escape

当然必须有解决方案吗?还是$escape_html{capture}不兼容?

0 投票
1 回答
124 浏览

smarty - 我是否总是需要在 if 中使用 isset?

以下是否可以接受,即使$my_flag可能没有设置?

我是否总是需要isset确保不会抛出通知,或者 Smarty3 是否会处理这些事情?

0 投票
1 回答
616 浏览

php - 聪明的 if 语句

我第一次使用 smarty 所以请不要作恶..希望有人可以帮助我解决这个问题。我在 page.tpl 中有以下代码:

加载页面时,我看到

它准确地显示了我编写的代码,尽管上面显示了正确的变量属性。有人知道我在做什么错吗?

谢谢

0 投票
1 回答
714 浏览

php - smarty中的数组赋值

我有一个数组并将其分配给 smarty via $smarty->assign('array', $array);,但我无法在模板中获取它。如何正确引用它?我试过:

有和没有$