1

I'm attempting to create a new page layout for Categories, here's what I have so far:

app/code/Karl/Subcategories/registration.php

<?php
use \Magento\Framework\Component\ComponentRegistrar;
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Karl_Subcategories', __DIR__);

app/code/Karl/Subcategories/etc/module.xml

<config>
    <module name="Karl_Subcategories" setup_version="1.0.0"/>
</config>

app/code/Karl/Subcategories/view/frontend/layouts.xml

<page_layouts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/PageLayout/etc/layouts.xsd">
    <layout id="subcategories">
        <label translate="true">Subcategories</label>
    </layout>
</page_layouts>

So far this is working, I now have a new option within the dropdown for "Custom Design > Page Layout".

But I'm having difficulty trying to define the actual page template which should be used and I'm unable to find much documentation on this.

app/code/Karl/Subcategories/view/frontend/page_layouts/subcategories.xml

<?xml version="1.0"?>
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd">
    <referenceBlock name="root">
        <action method="setTemplate">
            <argument name="template" xsi:type="string">Karl_Subcategories::subcategories.phtml</argument>
        </action>
    </referenceBlock>
</layout>

app/code/Karl/Subcategories/view/frontend/templates/subcategories.phtml

<?php
echo 'hi';

Any help is greatly appreciated.

1

You have keep subcategories.xml file inside app/code/Karl/Subcategories/view/frontend/page_layout folder. May be you have mistakes in folder name page_layout not page_layouts. plz check using above folder name and try again.

  • It's definitely supposed to be layouts.xml not layout.xml and page_layouts not page_layout because if I change these the option disappears from the dropdown, although it doesn't look like it's hitting the subcategories.xml file. – Karl Dec 17 '15 at 13:23
  • have you keep folder name page_layout? – Rakesh Jesadiya Dec 17 '15 at 13:26
  • Yes, tried both page_layout and page_layouts – Karl Dec 17 '15 at 13:27
  • you have to keep layouts.xml and page_layout/subcategories.xml file and try. – Rakesh Jesadiya Dec 17 '15 at 13:29
  • I have, still doesn't work. – Karl Dec 18 '15 at 9:06

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.