简体   繁体   English

Smarty:放大数组并将其分配给var

[英]Smarty: Implode an array and assign it to a var

I want to archieve the following: 我想存档以下内容:

"I am a descriptive sentence" “我是描述性的句子”

I put it in an array (for creating keywords for meta tags) via: 我通过以下方式将其放入数组(用于为元标记创建关键字)中:

[{assign var='meta_key_arr' value=' '|explode:$oEntry->FCLONGDESC_1}]                  

That works so far. 到目前为止有效。 My result is an array like that: 我的结果是这样的数组:

array([I],[am],[a],[descriptive],[sentence])

The goal is to get a String like that "I,am,a,descriptive,sentence" 目的是获得一个像“我,我,一个,描述性,句子”这样的字符串。

I wanted to implode the array seperated by a comma: [{', '|implode:$meta_key_arr}] 我想内插一个以逗号分隔的数组:[{','| implode:$ meta_key_arr}]

This works fine, but I want to assign the values to another variable $meta_key. 这工作正常,但我想将值分配给另一个变量$ meta_key。 Which does not work. 哪个不起作用。 I read the manual but the only thing I could find was the syntax above. 我读了手册,但唯一能找到的就是上面的语法。

[{assign var='meta_key' value=' '|', '|implode:$meta_key_arr}]

did not work. 不工作。 And this didn't work either. 而且这也不起作用。

[{assign var='meta_key' value=' ' ', '|implode:$meta_key_arr}]

How can I use the implode function correct? 如何正确使用爆破功能? There is a much easier way for sure. 有一种更简单的方法可以肯定。

The solution: 解决方案:

[{foreach from=$meta_key_arr item=mkey}]
   [{assign var='meta_key' value=', '|implode:$meta_key_arr}]
[{/foreach}]

您为什么不只使用原始字符串并用逗号替换空格?

[{assign var='meta_key' value=$oEntry->FCLONGDESC_1|replace:' ':', '}]

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

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