Magento 2 – Add Custom Block or Template to 2columns-left Layout

landing-pageslayoutmagento2update-handle

We are trying to add newsletter template to pages that are only have 2columns-left layout, for that we have created a custom module and added below code, but it seems it is not working. Can any one tell help us, what could be the issue.

app\code\Vendor\Module\view\frontend\layout\default.xml

 <?xml version="1.0"?>
    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
            <body>
            <referenceContainer name="page.bottom.container">
        <block class="Magento\Newsletter\Block\Subscribe" template="Magento_Newsletter::subscribe.phtml"/>
            </referenceContainer>
        </body>
    </page>

Best Answer

Add a custom container within your 2columns-left.xml within your theme and assign your custom block to this new container within your theme default.xml ?

UPDATE:

Add the following to add a custom container to your layout xml

[your-theme]/Magento_Theme/page_layout/2columns-left.xml

 <container name="newsletter.section" as="newsletter_section" label="Newsletter Section"/>

Add your .phtml to the container in your theme default.xml

[your-theme]/Magento_Theme/layout/default.xml

<referenceContainer name="newsletter.section">
    <block class="Magento\Newsletter\Block\Subscribe" name="newsletter" template="Magento_Newsletter::subscribe.phtml"></block>
</referenceContainer>   

If you haven't got these xml files within your theme you will need to duplicate them from the vendor folder.

Hope this helps you :)