In Magento 2, has anyone tried to add an update handle in "Custom Layout Update" on the category admin page? I've set the following on a category:
<update handle="my_handle_lorem_ipsum_lorem" />
And I created the following file in my current theme:
[theme dir]/Magento_Catalog/layout/my_handle_lorem_ipsum_lorem.xml
However, the update handle doesn't appear to be applied.
I know the XML directives in my_handle_lorem_ipsum_lorem.xml
are correct because they work correctly when placed in [theme dir]/Magento_Catalog/layout/catalog_category_view_id_123.xml
.
By debugging I've found that the "Custom Layout Update" attribute is handled here:
// \Magento\Catalog\Controller\Category\View::execute() [excerpt]
$layoutUpdates = $settings->getLayoutUpdates();
if ($layoutUpdates && is_array($layoutUpdates)) {
foreach ($layoutUpdates as $layoutUpdate) {
$page->addUpdate($layoutUpdate);
}
}
Tracing the source of $layoutUpdates
, I found that it ultimately gets set in _extractSettings()
of \Magento\Catalog\Model\Design
:
// \Magento\Catalog\Model\Design::_extractSettings() [excerpt]
$settings->setCustomDesign(
$object->getCustomDesign()
)->setPageLayout(
$object->getPageLayout()
)->setLayoutUpdates(
(array)$object->getCustomLayoutUpdate()
);
That pulls the entire string <update handle="my_handle_lorem_ipsum_lorem" />
from the category attribute. Does that mean it's trying to use the entire string as the handle name?
All I see is the call to addUpdate()
. There doesn't seem to be a call to any function of the Merge
class that would incorporate it into the overall layout XML.
In general, how should we add a handle in the category field "Custom Layout Update," and where and how should the file should be declared?