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

时间:2021-10-05 00:18:19

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. In short it should behave like implode() in php. Can someone please help me in achieving this in smarty template? Thanks in advance.

现在我想在smarty模板的div元素中将上述数组元素显示为逗号分隔值。简而言之,它应该像php中的implode()一样。有人可以帮助我在聪明的模板中实现这一目标吗?提前致谢。

1 个解决方案

#1


29  

Try this:

尝试这个:

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

It will give you what you are expecting. Cheers!!!

它会给你你所期待的。干杯!!!

#1


29  

Try this:

尝试这个:

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

It will give you what you are expecting. Cheers!!!

它会给你你所期待的。干杯!!!