2

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.

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

1 Answer 1

3

Try the code below

{{block class="Magento\Framework\View\Element\Template" template="Custom_Slider::slider.phtml"}}
Amit Bera
77.8k21 gold badges127 silver badges240 bronze badges
answered Sep 18, 2018 at 10:09
3
  • 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' Commented Sep 18, 2018 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 ? Commented Sep 18, 2018 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/ Commented Sep 18, 2018 at 10:57

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.