G
G
Genri_Rus2021-02-28 17:20:53
PHP
Genri_Rus, 2021-02-28 17:20:53

How to get key in twig array without using loop?

Here is an example php array:

$options => array(
  'instrumentation' => 'Приборы'
)


How to get key in twig?

Tried like this, but then only the first key is displayed:
{{ quote|keys|first}}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Soshnikov, 2021-03-01
@Genri_Rus

The attribute function will help you
https://twig.symfony.com/doc/2.x/functions/attribu...

Получить значение по ключу: attribute(myArray, myKey)
Получить ключ по номеру: myArray|keys|attribute|myKey

But it looks so perverted that it's better to write a custom function tweak and cover it with a test.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question