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– Ansar Husain2018年09月18日 10:04:53 +00:00Commented Sep 18, 2018 at 10:04
-
Do you mean this? namespace Custom\Slider\Block;Howliee– Howliee2018年09月18日 10:29:17 +00:00Commented Sep 18, 2018 at 10:29
-
what is path you have for slider.phtml in your module ?Ansar Husain– Ansar Husain2018年09月18日 10:30:46 +00:00Commented Sep 18, 2018 at 10:30
-
Custom/Slider/view/frontend/templates/slider.phtmlHowliee– Howliee2018年09月18日 10:33:26 +00:00Commented Sep 18, 2018 at 10:33
-
code looks right according to path {{block class="Custom\Slider\Block\Slider" template="Custom_Slider::slider.phtml"}}Ansar Husain– Ansar Husain2018年09月18日 10:38:37 +00:00Commented Sep 18, 2018 at 10:38
1 Answer 1
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– Howliee2018年09月18日 10:13:15 +00:00Commented 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 ?Richard Valsalan– Richard Valsalan2018年09月18日 10:53:58 +00:00Commented 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/Howliee– Howliee2018年09月18日 10:57:14 +00:00Commented Sep 18, 2018 at 10:57