Magento 2 - Creating a New Blank Template Block

If you want to insert some custom HTML into a page in Magento 2, you’ll need to add some layout XML and a template file.

The equivalent in Magento 1 is a <block type="core/template" template="path/to/template.phtml" name="block_name" />

In Magento 2 you achieve this by adding a <container> in your default.xml (or other layout file) with the following:

<referenceContainer name="container_name"> <!-- the name of the container you want to insert into -->
    <container name="new_container" htmlClass="container_css_class" htmlTag="div">
        <block class="Magento\Framework\View\Element\Template" template="Magento_Theme::path/to/template.phtml" name="block_name" />
    </container>
</referenceContainer>

Then create a template in app/design/frontend/<your_vendor>/<your_theme>/Magento_Theme/path/to/template.phtml

Remember to flush all caches.


Tags: magento2magentotemplatetheme