1

I would like help working out how to add a custom container as a 'Layout Update' for a widget..

Currently, I only have the 3 basic options to choose from (Main Content Area, Siderbar Main and Sidebar Additional), but I would like to be able to add widgets to containers that I've created through various default.xml files.

Specifically, I'm trying to include the Recently Viewed widget. I have tried updating module-reports/etc/widget.xml, adding an extra inside the , however that doesn't seem to work..

How can I use a customer container?

Thanks, Luke

2

As it turns out, the custom container that I had created didn't have a label attribute, so Magento was ignoring it as a possible layout destination

2

Note: The below has been tested up to Magento 2.2.8

I had a similar issue and have build a module to do this exact same thing, but it's in a private repository so I can't give you the link, I can however give you the code; note I've changed the namespace to LD (shorthand for Luke Denton - it can be whatever you want, as long as it's consistent). Simply upload the below files to app/code/LD/Reports

registration.php

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'LD_Reports',
    __DIR__
);

etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="LD_Reports" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Reports"/>
        </sequence>
    </module>
</config>

ets/widget.xml

<?xml version="1.0" encoding="UTF-8"?>
<widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Widget:etc/widget.xsd">
    <widget id="recently_viewed">
        <containers>
            <container name="my.additional.container">
                <template name="default" value="list_default" />
                <template name="names_only" value="list_names" />
                <template name="images_only" value="list_images" />
            </container>
        </containers>
    </widget>
</widgets>

Then in your theme you need a container with a corresponding name and label.

1
  • 1
    I can confirm it works for 2.2.8 – Daniel May 8 '19 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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