How to check if there is a user is loggedin? Normaly you do this like:

if ( is_user_logged_in() ) { // do something }

but how you do this within a Timber template? some thing like?:

{% if userloggedin %} //do somthing {% endif %}

  • 1
    I am not familiar with Timber but can't you pass a boolean variable inside your template? Like $context['userLoggedIn'] = is_user_logged_in(); Timber::render('index.twig', $context); – Laxmana Feb 21 '17 at 11:03
  • Also a good idea. The benefit of the user object is that all user related stuff is available – Maarten Heideman Feb 21 '17 at 11:22
  • I agree, it is better to use the user object. I don't know how Timber works so I didn't know the existence of user object :) – Laxmana Feb 21 '17 at 11:23

Found it already, to do this you can use the 'user' object:

{% if user %} Hello {{ user.user_nicename }} {% else %} you are not loggedin {% endif %}


Just to elaborate, an alternative is:

{% if function( 'is_user_loggged_in') %}
... your logged in code here
{% endif %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.