I'm following an exercise in the ebook 'No-Frills-Magento-2-Layout' by Alan Storm (excellent book so far btw) and am coming across a slight issue for which I am not sure what I am doing wrong.
I am trying to create a new theme with the intention of adding a new block to the catalog_category_view
layout template.
I have the following code structure:
/design
/frontend
/Pulsestorm
/dram
/Magento_Catalog
registration.php
theme.xml
/layout
catalog_category_view.xml
/templates
hello.phtml
The files contents are as follows:
registration.php:
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::THEME,
'frontend/Pulsestorm/dram',
__DIR__
);
theme.xml:
<?xml version="1.0"?>
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
<title>Pulsestorm Dram</title>
<parent>Magento/luma</parent>
<media>
<preview_image/>
</media>
</theme>
catalog_category_view.xml:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block name="pulsestorm_magento_catalog_category_view_example" class="Magento\Framework\View\Element\Template" template="hello.phtml"/>
</referenceContainer>
</body>
</page>
hello.phtml:
<h2>Hello Category Listing Page</h2>
I then registered the theme in admin in Content -> Design -> Themes
for each website listed (the default websites that ship with Magento 2).
I then cleared the cache: magento cache:clean
and then navigated to: [development-web-address]/gear/fitness-equipment.html
but I then get the following exception:
1 exception(s):
Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: 'hello.phtml' in module: '' block's name: 'pulsestorm_magento_catalog_category_view_example'
Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: 'hello.phtml' in module: '' block's name: 'pulsestorm_magento_catalog_category_view_example'
#0 /srv/magento/vendor/magento/framework/View/Element/Template.php(300): Magento\Framework\View\Element\Template->fetchView(false)
#1 /srv/magento/vendor/magento/framework/View/Element/AbstractBlock.php(667): Magento\Framework\View\Element\Template->_toHtml()
#2 /srv/magento/vendor/magento/framework/View/Layout.php(557): Magento\Framework\View\Element\AbstractBlock->toHtml()
#3 /srv/magento/vendor/magento/framework/View/Layout.php(533): Magento\Framework\View\Layout->_renderBlock('pulsestorm_mage...')
...
I am expecting <h2>Hello Category Listing Page</h2>
to be displayed after the product listings. Why am I getting this exception? From the exception message, I'm guessing that it may have something to do with the blank module name but I'm not sure why it is blank.