How to convert string to array in Twig
what I need:
in the following way:
["Product_Name"]=> string(362) "Top End Transport System,Band Combiner Devices,Our Mid Level Transport System,The Introductory Transport System,In-Line Amplification Systems,Intelligent Ethernet Access System,Ethernet Access System,Intelligent Ethernet Access System (Ieas 05),Intelligent Ethernet Access System (Ieas 06),Intelligent Ethernet Access System (Ieas 03),Ethernet Aggregation Device" }
- Im using php slice function in such a way that i have to check line up to line 5.
- ex: upper level transport system, mid-level transport system, introductory transport system, built-in amplifier systems, intelligent network access system.
- I need up to the first five lines.
- I am referring to the article http://twig.sensiolabs.org/doc/filters/split.html
here's the code:
{% set foo = item.Product_Name|split(',') %}
{{ dump (foo) }}
{% for i in item.Product_Name|slice(0, 5) %}
{{ dump(i) }}
{% endfor %}
- Slice function for array, so please tell me how to convert product name to array in twig
+3
user2818060
source
to share
1 answer
You need to flip your variable foo
to print your product snippet foo
to get the first five namesfoo|slice(0, 5)
{% set foo = item.Product_Name|split(',') %}
{% for i in foo|slice(0, 5) %}
{{ dump(i) }}
{% endfor %}
+1
M khalid junaid
source
to share