简体   繁体   English

如何在smarty模板中将数组转换为逗号分隔的字符串?

[英]How to convert an array into comma separated strings in smarty template?

I've an array titled $preview_data assigned to smarty template as follows: 我有一个名为$preview_data的数组,分配给smarty模板,如下所示:

Array
(
  [applicable_states] => Array
        (
            [0] => 1
            [1] => 3
            [2] => 4
            [3] => 10
            [4] => 11
        )

)

Now I want to show the above array elements as comma separated values in a div element of a smarty template. 现在,我想将以上数组元素显示为smarty模板的div元素中的逗号分隔值。 In short it should behave like implode() in php. 简而言之,它的行为应类似于php中的implode() Can someone please help me in achieving this in smarty template? 有人可以帮我实现聪明的模板吗? Thanks in advance. 提前致谢。

Try this: 尝试这个:

{', '|implode:$preview_data.applicable_states}

It will give you what you are expecting. 它会给您您所期望的。 Cheers!!! 干杯!!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM