Dynamic Layout Handle

A layout handle is a XML tag which allow to determine which blocks are loaded depending on the current path.

For example, contentmanager_index_content is the handle which will be used on a content view page.

The default layout for a content view is:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> 
<head>
<"Blackbird_ContentManager::css/content.css" />

<body>
<referenceContainer name="content">
<referenceBlock name="page.main.title" remove="true"/>
<block class="Blackbird\ContentManager\Block\View" name="contentmanager_view" />



The dynamic layout handle will permits to add specific block or layout for a defined content type.

Let's say we want to add a cms block in the left column of our blog content type. We will use then CONTENT_TYPE_VIEW_blog.xml as layout file 

<referenceContainer name="left">
<block class="""Magento\Cms\Block\Block" name="my-custom-block">
<action method="setBlockId">my-custom-blockargument>action>
block>

 

Let's say we want to add a cms block in the left column of our archive content list (only created from the backend). We will use then CONTENT_LIST_VIEW_archive.xml as layout file

<referenceContainer name="left">
<block class="Magento\Cms\Block\Block" name="my-custom-block">
<action method"setBlockId">my-custom-blockargument>action>
block>
<
/referenceContainer>
loader
Chargement en cours...