ensure_logged_in with handlebars?

(Christopher Heald) #1

Based on @sam’s work on the minimal topic list design I would like to show a custom menu item in the header but only to logged in users. Is this possible? Is there a way to determine if a user is logged in with handlebars?

application_controller.rb has ensure_logged_in:

def ensure_logged_in
  raise Discourse::NotLoggedIn.new unless current_user.present?

but I don’t know how to access it, or if this is accessible via handlebars at all.

(Sam Saffron) #2
{{#if currentUser}}

Should do the trick, we inject it.

(Christopher Heald) #3

Can I use handlebars to show conditional content in the custom header?

Possibly something wrapped in <script type='text/x-handlebars' data-template-name='list/topic-list-item.raw'> if there is a template for the custom header?

We have a custom menu in the header and I would like to include a menu item that’s only visible to logged in users.