Does Magento 2 have such handle as customer_logged_in? If yes how can I use it?

I tried to create


and added there <referenceBlock name="content" remove="true" />

But content block wasn't removed. I renamed handle file to default and block was successfully removed.

What am I doing wrong?

4 Answers 4


Answer to your question is definitely no, there is no customer_logged_in handle anymore, I've digged into the code and could not find any layout handle that could do the trick.

On top of that under \dev\tests\static\testsuite\Magento\Test\Legacy\LayoutTest.php you can find the following code:

 * List of obsolete nodes
 * @var array
protected $_obsoleteNodes = [

Which to me, clearly tells us that the customer_logged_in layout handle is obsolete now.

See Fabian's answer for explanations about how it is done now in Magento 2.

  • 1
    those events are triggered when the customer logs in and when he logs out, not on every request. Commented Mar 15, 2016 at 12:33

If anyone is still struggling with this I wrote a quick module that adds the customer_logged_in and customer_logged_out layout handles for you to use just like in Magento 1


Enjoy !


As others have pointed out, these handles are now gone. If you look at the Magento_Customer module, you'll see that blocks like the registration link are always added but not rendered if the customer is logged in. It looks like this is now the preferred way to show elements conditionally depending on login state.

But this is not a solution for removing blocks based on their name, that were defined somewhere else. You could recreate the feature with an observer for layout_load_before that calls $layout->addHandle('customer_logged_in') if the customer is logged in.

  • Thanks for your response. Sure I thought about adding handle that in my custom module. But it could look like spike and I wanted to use more native way. Thanks for explanation and example
    – zhartaunik
    Commented Mar 15, 2016 at 12:44

This is very stupid. I need to load block/template/resourse only customer have permission, not just loggin or loggout. But i need to write 1000 lines of code to check if user have permission to see this. Just beautiful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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