- Issue created by @jmary
- Status changed to Closed: works as designed
over 1 year ago 8:40am 1 September 2023 - 🇭🇰Hong Kong jmary
The preprocess function should be:
function acc_preprocess_field(&$variables) { $element = $variables['element']; // Check if the field is the one we are interested in if ($element['#field_name'] === 'field_complexity') { // Assuming you have an entity in $element $entity = $element['#object']; // Check if the field exists on this entity if ($entity->hasField('field_complexity') && !$entity->field_complexity->isEmpty()) { // Get the referenced taxonomy term. $term_reference_item = $entity->get('field_complexity')->first(); // Get the term entity. $term = $term_reference_item->entity; // Get term ID. $term_id = $term->id(); // Add term ID to variables. $variables['acc_term_id'] = $term_id; } } }
Then the variable is available in my template field: field--node--field-complexity--issues.html.twig
Also, I had to check the permissions and ownership of the templates. The reason my templates were not used was because they were not readable by www-data.
Sorry for the noise. It might help someone facing similar issues.