Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To verify if a particular key in an array is present using Twig, you can use the 'in' operator. The 'in' operator checks if a value is present in an array or not.

Here's an example:

{% set myArray = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'} %}

{% if 'key2' in myArray %}
    Key2 is present in myArray
{% else %}
    Key2 is not present in myArray
{% endif %}

In the above example, we have an array named 'myArray' with three key-value pairs. We are checking if the key 'key2' is present in the array using the 'in' operator. If the key is present, the message 'Key2 is present in myArray' will be displayed, otherwise 'Key2 is not present in myArray' will be displayed.