Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By AndyLicht on
Hi,`
i´m using D8 and i need some help with my field--node--field-fieldname.twig.html
I want that my field is only shwon for logged in users, so i tested:
{{logged_in}} and {{is_admin}}
these variables are ever 1, so i think i do not get the right variables, or i can not use them.
I want to do it like this:
{% if 'Test' starts with 'T' %}
{% set field_name_class = field_name|clean_class %}
{%
set classes = [
'field',
'field-' ~ entity_type|clean_class ~ '--' ~ field_name_class,
'field-name-' ~ field_name_class,
'field-type-' ~ field_type|clean_class,
'field-label-' ~ label_display,
'clearfix',
]
%}
{%
set title_classes = [
'field-label',
label_display == 'inline' ? 'inline',
]
%}
<p>{{logged_in }}</p><p>{{is_admin}}</p> //everytime both are 1!!!
<div{{ attributes.addClass(classes) }}>
{% if not label_hidden %}
<h3{{ title_attributes.addClass(title_classes) }}>{{ label }}</h3>
{% endif %}
<ul{{ content_attributes.addClass('links', 'field-items','meinoverride') }}>
{% for item in items %}
<li{{ item.attributes }}>{{ item.content }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
Thanks for helping me.
Comments
Hi,
Hi,
I think you shoulf have a look at this link :
is_admin: Boolean indicating whether the theme is the admin theme or not.
another link:
logged_in: Flag for authenticated user status. Will be true when the current user is a logged-in member.
Are cache tables managed properly ?