0

I've created a module that includes a custom page. I can set a template block for the page title as follows:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="page.main.title" template="JR2_MonthlySubscription::monthly_subscription.phtml" />
        <!--
        <referenceBlock name="page.main.title">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">MYA_Subscribe::title.phtml</argument>
            </action>
        </referenceBlock>
        !-->
    </body>
</page>

This works fine, but how do I set a template for the actual page content? I've tried adding a reference block for page.wrapper to no avail. The documentation doesn't seem to mention the available page options for name.

1
  1. You have to add below code into your layout XML file
<referenceContainer name="content">
    <block class="Magento\Framework\View\Element\Template" name="custom-content" template="JR2_MonthlySubscription::content.phtml" />
</referenceContainer>
  1. Add your phtml file and custom content in phtml file. app/code/JR2/MonthlySubscription/view/frontend/templates/content.phtml
<h1>Custom Content</h1>

It will show at your cusom page.

2
  • Is there a list of container and block names? I can't find them anywhere in the Magento documentation. May 10 at 5:58
  • 1
    There are some pre-defined containers but you can create yours as well. You can refer to this devdocs.magento.com/guides/v2.4/frontend-dev-guide/layouts/… Or most of the common containers you can find in vendor/magento/module-theme/view/frontend/layout/default.xml
    – Mital Shah
    May 10 at 6:46

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.