Get array elements from selectize field


I’d like to get the values from a selectize field.
I have this in item.yaml:
   type: selectize
   multiple: true
   size: medium
   label: Author

In blog-item.html.twig I have:

{% if %}
    {% set authors = %}
{% else %}
    {% set authors =  taxonomylist.get() %}
{% endif %}

{% for author,value in authors['author'] %}
   <a href="{{ blog.url|rtrim('/') }}/author{{ config.system.param_sep }}{{ author }}" itemprop="keywords">{{ tag }}<span rel="author"> {{ author }} </span></a>
{% endfor %}

I can get the values from the author taxonomy in options tab, but I don’t know how I can get that values from the (in blog item tab). This is a selectize field. The result in is:

    - tag1
    - author1  
    - author2

I’d also like to be able to get the values from, in case the user doesn’t use the author taxonomy in options tab.

Any idea for this (sorry, I’m begginer with PHP and Twig)
Thanks in advanced.

What happens if you change two lines

    {% set authors = %}


{% for author,value in authors %}

I’m not at my PC now, but looking at code I see you have a level of author in taxonomy, but there’s no another level of author in author, which you try to loop through

Hi @Karmalakas

Your suggestion not work. Nevertheless, I not have problem with values from taxonomylist ( {% set authors = taxonomylist.get() %}, work fine ).
I’d like to get values form selectize field as array elements, but I don’t know the way to do this.

You’re looping through
In header taxonomy you have
In header author you have just author
When you get authors from header taxonomy, you end up with
When you get authors from header author, you end up with authors
In second case you don’t have to loop through.

What was your code after my suggestion?

Hi @Karmalakas

In the end I have chosen to use the author taxonomy, instead of using the blueprint in the .yaml template. The final code is the following:

{% if config.plugins.taxonomylist.enabled and is not empty %}
 <span><i class="fas fa-user"></i></span>
 {% for author in %}
     <a href="{{ blog.url|rtrim('/') }}/author{{ config.system.param_sep }}{{ author }}" rel="author" itemprop="keywords">{{ author }}</a>
     {% if not loop.last %}, {% endif %}
 {% endfor %}
{% endif %}

However, it is easy to get the values of a selectize field array with the function: “array(”