1

I've created multiple custom pages like a contact page and FAQ page but both the pages and the containers I've labeled don't show up in the widget panel.

What's the right way to add widgets to your custom pages?

1

2 Answers 2

2

add a page_types.xml within your module. The path will be etc/frontend/page_types.xml

in this you can define the page_types as below

<?xml version="1.0"?>
<page_types xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_types.xsd">
    <type id="mycustom_controller_index" label="My Custom Intex Controller"/>
</page_types>

after that, you can select this into Display On:: Specified Page section into the admin area of the widget. as shown below Specified Page

3
  • Say I have a design/frontend/vendor/theme/Magento_Theme/page_layout/gm_faq.xml file. How would I use the page_types.xml file in this situation? It looks like the id in page_types.xml points to a controller but in this case there doesn't seem to be any.
    – Alphaegen
    Commented Nov 17, 2020 at 10:11
  • there should be a controller for faq so you can just add page_types.xml defining that within Magento_Theme/layout/ Commented Nov 17, 2020 at 10:26
  • I'm not sure if we use a controller. We added the gm_faq.xml file and added the layout to the layout.xml file. After that we were able to select the layout in a page under the pages tab in admin.
    – Alphaegen
    Commented Nov 17, 2020 at 11:12
1

First: create new page layout under app/design/frontend///Magento_Theme/layouts.xml. Assign template to specific page(s)

<?xml version="1.0" encoding="UTF-8"?>
   <page_layouts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/PageLayout/etc/layouts.xsd"> 
       <layout id="layout-id">
           <label translate="true">Layout name</label>
        </layout>
   </page_layouts>

Clear cache:

php bin/magento cache:cle

enter image description here

Second: Create new page type in your custom module and map new page in your widget

<?xml version="1.0"?>
<page_types xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_types.xsd">
    <type id="cms_page_view_id_About-us" label="About Us"/>
</page_types>

Clear cache:

php bin/magento cache:clean

enter image description here

References:

  1. Create a new layout
  2. Mapping widget and layout

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.