I would like to change a fixed array name to a dynamic array name. Within a
set item_classes = [
item.original_link.nid and item.original_link.p6 and item.original_link.in_active_trail ? 'active',
]
This works because the 'nid' and p6 are the same and unique.
Within the item.original_link array there are 19 values:
'nid' => string(3) "114" - Node ID
'bid' => string(3) "100"
'pid' => string(3) "111"
'has_children' => string(1) "0"
'weight' => string(1) "0"
'depth' => string(1) "3" - Page Depth
'p1' => string(3) "100"
'p2' => string(3) "111"
'p3' => string(3) "114" - P+Depth
'p4' => string(1) "0"
'p5' => string(1) "0"
'p6' => string(1) "0"
'p7' => string(1) "0"
'p8' => string(1) "0"
'p9' => string(1) "0"
'in_active_trail' => boolTRUE
'access' => boolTRUE
'title' => string(21) "Development.twig.html"
'options' => array(0)
I need to set the value of the item.original_link.p6 to a dynamic value of: 'p + depth'.
As in this example, the value would be item.original_link.p3.
I hope I have explained this in enough detail for someone to help or give me direction.
I have added a set variable as below:
{% set my_var = [ ('p' ~ item.original_link.depth ), ] %}
This gives me the desired dynamic variable, but when I use this in the next set as below:
{% set item_classes = [ item.original_link.nid and item.original_link.my_var and item.original_link.in_active_trail ? 'is_active', ] %}
it returns NULL