14
March
In a Drupal 8 views template, you can check if a user is logged in by using the following code
{% if logged_in %} Welcome, {{ user.name }} {% else %} {{ path('user.login') }} {% endif %}
Explanation:
Note: The logged_in variable and user variable are only available in certain views templates, such as views-view.html.twig and views-view-fields.html.twig. If you're using a different views template, these variables may not be available, so be sure to check the documentation for the specific template you're using.
© 2023.ZedAngle. All Rights Reserved.