Missing 'selected' in twig

Created on 18 September 2020, about 4 years ago
Updated 29 April 2024, 7 months ago

$variables['selected'] is missing for bef-links.html.twig template.

[ORIGINAL ISSUE]
I tried for hours to change the class in the link. On the 8.3 version I was able to create a simple bef-links.html.twig :

{%
  set classes = [
    'bef-links',
  ]
%}
<input type="hidden" name="{{ element["#name"] }}" value="{{ element["#value"] }}" />
<div{{ attributes.addClass(classes) }}>
  {% set current_nesting_level = 0 %}
  {% for child in children %}
    {% set item_attribute = create_attribute() %}
    {% set item = attribute(element, child) %}
    {% if child in selected %}
        {% set item_attribute = item_attribute.addClass(['active']) %}
    {% endif %}
        <a href="{{ item['#url'] }}" {{ item_attribute.addClass(['btn', 'btn-outline-secondary' , 'btn-sm']) }}> 
           {{ item['#title']  }} 
        </a>
  {% endfor %}
</div>

But with the 8.4.x it seem that {% if child in selected %} has no effect.

This is how I tried to adapt the template

{%
  set classes = [
    'bef-links',
    is_nested ? 'bef-nested'
  ]
%}
{% set is_nested = true %}
<div{{ attributes.addClass(classes) }}>
  {% set current_nesting_level = 0 %}
  {% for child in children %}
    {% set item = attribute(element, child) %}
    {% if item in selected %}
      {% set new_nesting_level = attribute(depth, child) %}
      {% set item = item|merge({'#attributes': {'class': ['active', 'btn', 'btn-outline-secondary' , 'btn-sm']}}) %}
    {% else %}
      {% set item = item|merge({'#attributes': {'class': ['btn', 'btn-outline-secondary' , 'btn-sm']}}) %}
    {% endif %}
    {% set new_nesting_level = attribute(depth, child) %}
    {{ item }}
    {% set current_nesting_level = new_nesting_level %}
  {% endfor %}
</div>
πŸ› Bug report
Status

Fixed

Version

6.0

Component

Code

Created by

πŸ‡¨πŸ‡­Switzerland gagarine

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024