在 smarty 中分配关联数组

发布于 2024-10-19 21:46:01 字数 429 浏览 0 评论 0原文

所以我想要实现的是将多个值分配给我想要的索引上的 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 技术交流群。

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

发布评论

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

评论(1

偏闹i 2024-10-26 21:46:02

我找到了解决方法。所需的关联数组用于 HTML Select 标记。所以我只是使用带有值和输出属性的 {html_options} 而不是选项。我分配了一个数组仅用于值,另一个数组仅用于输出。

我有这个:

{html_options options=$paymentTypes}

但我不想显示 paymentTypes 数组中的所有值,但我必须将它们放在数组中。所以我所做的是:

{assign var='paymentTypesOutput' value=','|explode:"$paymentTypes[50],
$paymentTypes[51],$paymentTypes[11],$paymentTypes[10],$paymentTypes[12],
$paymentTypes[99],$paymentTypes[100]"}

{assign var='paymentTypesValues' value=','|explode:"50,51,11,10,12,99,100"}

{html_options values=$paymentTypesValues output=$paymentTypesOutput}

这不是最优雅的解决方案 - 但它有效。

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:

{html_options options=$paymentTypes}

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:

{assign var='paymentTypesOutput' value=','|explode:"$paymentTypes[50],
$paymentTypes[51],$paymentTypes[11],$paymentTypes[10],$paymentTypes[12],
$paymentTypes[99],$paymentTypes[100]"}

{assign var='paymentTypesValues' value=','|explode:"50,51,11,10,12,99,100"}

{html_options values=$paymentTypesValues output=$paymentTypesOutput}

It's not the most elegant solution - but it works.

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