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

跟風遠走 提交于 2019-11-29 06:17:28

问题


I've an array titled $preview_data assigned to smarty template as follows:

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.


回答1:


Try this:

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

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



来源:https://stackoverflow.com/questions/23306281/how-to-convert-an-array-into-comma-separated-strings-in-smarty-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!