in twig file after spliting the value i’m getting output like this in a browser
<select class="form-control" id="eventCustomerID" name="eventCustomer">
<option value="64" name="64">64</option>
<option value="demou22_6hhh" name="demou22_6hhh">demou22_6hhh</option>
</select>
but i need an output to be like this
<select class="form-control" id="eventCustomerID" name="eventCustomer">
<option value="64" name="64">demou22_6hhh</option>
</select>
this is my code in a twig file
<select class="form-control" id="eventCustomerID" name="eventCustomer">
{% set tags = 64|demou22_6hhh|split('|',1) %}
{% for x in tags %}
<option value="{{ x }}" name="{{ x }}">{{ x }}</option>
{% endfor %}
</select>
I am stuck with this can someone help me out with this issue.
>Solution :
To achieve your required output, you shouldn’t use a for loop, but access the elements directly.
<select class="form-control" id="eventCustomerID" name="eventCustomer">
{% set tags = "64|demou22_6hhh"|split('|') %}
<option value="{{ tags[0] }}">{{ tags[1] }}</option>
</select>
Note about the second argument you are passing to the filter split
Not sure why you are passing 1 as the second argument. By setting this parameter to 1, you are limiting the output to one element in the array. More information here.