Add Frontend Template in Magento 2

Published Thursday, January 16, 2020

File List

  • Joki/FrontendTemplate/registration.php
  • Joki/FrontendTemplate/etc/module.xml
  • Joki/FrontendTemplate/view/frontend/layout/catalog_product_view.xml
  • Joki/FrontendTemplate/view/frontend/templates/catalog/product/view/after-content.phtml

registration.php [copy] [hide]

 
  1<?php
  2use \Magento\Framework\Component\ComponentRegistrar;
  3
  4ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Joki_FrontendTemplate', __DIR__);
 

etc/module.xml [copy] [hide]

  1<?xml version="1.0"?>
  2<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
  3    <module name="Joki_FrontendTemplate">
  4        <sequence>
  5            <module name="Magento_Catalog" />
  6        </sequence>
  7    </module>
  8</config>

view/frontend/layout/catalog_product_view.xml [copy] [hide]

  1<?xml version="1.0"?>
  2<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
  3    <body>
  4        <referenceContainer name="content">
  5            <block class="Magento\Framework\View\Element\Template" name="after.content" template="Joki_FrontendTemplate::catalog/product/view/after-content.phtml" after="-" />
  6        </referenceContainer>
  7    </body>
  8</page>

view/frontend/templates/catalog/product/view/after-content.phtml [copy] [hide]

 
  1<p>This comes after content.</p>