I’d like to set a variable in my node.html.twig
template:
{% set title = label %} {{ content }}
The content consists of one field visible only, which has it’s own template:
file-link.html.twig
How can I access the title
variable of the node template in the file template? I am not sure if importing or extending is the right way since that might cause infinite recursion?
Edit
The file template looks like this (from the bootstrap theme):
{% spaceless %} {% set classes = [ icon_only ? 'icon-only', not icon_only ? 'icon-' ~ icon_position|clean_class ] %} <span{{ attributes.addClass(classes) }}> {% if icon_only %} <span class="file-icon">{{ icon }}</span> <span class="sr-only"> <span class="file-link">{{ link }}</span> <span class="file-size">{{ file_size }}</span> </span> {% else %} {% if icon_position == 'after' %} <span class="file-link">{{ link }}</span><span class="file-size">{{ file_size }}</span><span class="file-icon">{{ icon }}</span> {% else %} <span class="file-icon">{{ icon }}</span><span class="file-link">{{ link }}</span><span class="file-size">{{ file_size }}</span> {% endif %} {% endif %} </span> {% endspaceless %}
Within that template I’d like to print the title of the respective node:
<span class="file-link">{{ link }}</span> <span class="file-node-title">{{ title }}</span> {# << #} <span class="file-size">{{ file_size }}</span>