Hi.
I’d like to get the values from a selectize field.
I have this in item.yaml:
header.author:
type: selectize
multiple: true
size: medium
label: Author
In blog-item.html.twig I have:
{% if page.header.author %}
{% set authors = page.header.author.get() %}
{% 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 page.header.author (in blog item tab). This is a selectize field. The result in item.md is:
taxonomy:
tag:
- tag1
author:
- author1
author:
- author2
I’d also like to be able to get the values from header.author, 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 = taxonomylist.author.get() %}
and
{% 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 authors.author
In header taxonomy you have taxonomy.author
In header author you have just author
When you get authors
from header taxonomy, you end up with authors.author
When you get authors
from header author, you end up with authors
In second case you don’t have authors.author
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 header.author blueprint in the .yaml template. The final code is the following:
{% if config.plugins.taxonomylist.enabled and page.taxonomy.author is not empty %}
<span><i class="fas fa-user"></i></span>
{% for author in page.taxonomy.author %}
<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(page.header.author)”