given front matter with an array as such
+++
[extra]
features = [
{name="Weight", value="1.12 kg"},
{name="Dimensions", value="4 x 8 m"},
]
is it possible to select one matching a selector along the lines of
page.extra.features[name='Weight']
Possibly a bit verbose but maybe something like this? If I understood correctly.
{% for feature in page.extra.features %}
{% if feature.name is matching("Weight") %}
{{ feature.name }}
{% endif %}
{% endfor %}
Corresponding tera docs.
Yes, i’m currently doing that. It’s nasty.
I was hoping some short cut existed for accessing objects.
its possible to access a value using the key
{{ page.extra['title'] }}
and also possible to access an object (not within an array) given
+++
[extra]
weight = {unit="kg", value=1.2}
both forms access the object in the template
{{ page.extra.weight.value }} {{ page.extra.weight.unit }}
{{ page.extra.weight['value'] }} {{ page.extra.weight['unit'] }}
but not for accessing an object WITHIN an array.
+++
[extra]
features = [
{name="Weight", value="1.12 kg"},
{name="Dimensions", value="4 x 8 m"},
]
ill try the some tera ‘built-ins’
The tera filter looks promising
page.extra.feature | filter(attribute='name', value="Weight")}}
Looks like it returns an array of object. Now to access the first element in the array.
{% set x = page.extra.feature | filter(attribute='name', value="Weight") | first %}
{{x}}
Would like to access that in one line but this is a good start