Magento 2 – How to Use the Layout Handle customer_logged_in

layoutmagento2update-handlexml

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

I tried to create

../view/frontend/layout/customer_logged_in.xml

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?

Best Answer

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 = [
    'PRODUCT_TYPE_simple',
    'PRODUCT_TYPE_configurable',
    'PRODUCT_TYPE_grouped',
    'PRODUCT_TYPE_bundle',
    'PRODUCT_TYPE_virtual',
    'PRODUCT_TYPE_downloadable',
    'PRODUCT_TYPE_giftcard',
    'catalog_category_default',
    'catalog_category_layered',
    'catalog_category_layered_nochildren',
    'customer_logged_in',
    'customer_logged_out',
    'customer_logged_in_psc_handle',
    'customer_logged_out_psc_handle',
    'cms_page',
    'sku_failed_products_handle',
    'catalog_product_send',
    'reference',
];

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.

Related Topic