在 smarty 中分配关联数组
所以我想要实现的是将多个值分配给我想要的索引上的 smarty 数组。很难描述它,所以我只是展示它:(
{assign var='paymentTypes'
value=','|explode:"$paymentMethods[50],$paymentMethods[51],
$paymentMethods[11],$paymentMethods[10],$paymentMethods[12],
$paymentMethods[99],$paymentMethods[100]"}
为了可读性而格式化)
所以现在我有一个 paymentTypes 数组,其值从 0 开始放置在键上。我想要的是保留 paymentMethods 数组中的键- 50, 51, 11.. 等。
并且必须完全在 Smarty 模板文件中完成。感谢您的任何想法。
So what I'm trying to achieve is assign multiple values in to a smarty array on the indexes that I want. It's hard to describe it, so I'll just show it:
{assign var='paymentTypes'
value=','|explode:"$paymentMethods[50],$paymentMethods[51],
$paymentMethods[11],$paymentMethods[10],$paymentMethods[12],
$paymentMethods[99],$paymentMethods[100]"}
(Formatted for readability)
So now I have a paymentTypes array with the values placed on the keys starting from 0. What I want is to keep the keys that were in paymentMethods array - 50, 51, 11.. etc.
And it has to be done totally in Smarty template file. Thanks for any ideas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决方法。所需的关联数组用于 HTML Select 标记。所以我只是使用带有值和输出属性的 {html_options} 而不是选项。我分配了一个数组仅用于值,另一个数组仅用于输出。
我有这个:
但我不想显示 paymentTypes 数组中的所有值,但我必须将它们放在数组中。所以我所做的是:
这不是最优雅的解决方案 - 但它有效。
I've found a workaround. The needed associative array was for a HTML Select tag. So I just used {html_options} with value and output attributes instead of options. I assigned one array just for values and another just for output.
I had this:
But I didn't want to show all of the values from paymentTypes array, but I had to have them in the array. So what I did was this:
It's not the most elegant solution - but it works.