1

I'm struggling including my custom module/block template into a static CMS page.

Here's my block code:

<block class="Magento\Framework\View\Element\Template" name="custom_slider_block" template="Custom_Slider::slider.phtml" />

How would I implement this in a static CMS page?

Edit:

I've added a block file with the following code:

<?php
 namespace Custom\Slider\Block;

 class Slider extends \Magento\Framework\View\Element\Template
 {
   public function _prepareLayout()
  {
    return parent::_prepareLayout();
   }
 }

and changed my block call to:

{{block class="Custom\Slider\Block\Slider" template="Custom_Slider::slider.phtml"}}

But now I get the error:

Error filtering template: Invalid block type: Custom\Slider\Block\Slider

Edit 2:

Got it working, realised I hadn't included a registration.php file to actually enable the module.

  • What is your Block class ? – Ansar Husain Sep 18 '18 at 10:04
  • Do you mean this? namespace Custom\Slider\Block; – Howliee Sep 18 '18 at 10:29
  • what is path you have for slider.phtml in your module ? – Ansar Husain Sep 18 '18 at 10:30
  • Custom/Slider/view/frontend/templates/slider.phtml – Howliee Sep 18 '18 at 10:33
  • code looks right according to path {{block class="Custom\Slider\Block\Slider" template="Custom_Slider::slider.phtml"}} – Ansar Husain Sep 18 '18 at 10:38
2

Try the code below

{{block class="Magento\Framework\View\Element\Template" template="Custom_Slider::slider.phtml"}}
  • I tried your solution Richard and got this error: Error filtering template: Invalid template file: 'Custom_Slider::slider.phtml' in module: '' block's name: 'magento\framework\view\element\template_0' – Howliee Sep 18 '18 at 10:13
  • Just a couple of questions, 1) What is the name of your custom Module 2) Do you have a template called Slider.phtml file ? – Richard Valsalan Sep 18 '18 at 10:53
  • The module is called Custom_Slider, Custom being the vendor. I do have a template called slider.phtml, lower case "s" which sits in Custom/Slider/view/frontend/templates/ – Howliee Sep 18 '18 at 10:57

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.