Check if the user is logged-in in a theme
In Drupal 7 we can simply check if the current user is logged-in in a theme by checking $GLOBAL['user']->uid
or using user_is_logged_in()
.
How can I check if a user is logged-in in a page template, in Drupal 8?
A solution is to manually check in hook_preprocess_page()
, but since this is very popular, I think Drupal provides something by default for the Twig theme engine.
This article was republished from its original source.
Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.