I created a module with a Custom Widget. When logging into the admin, going to content->widgets
, creating an instance, and setting that instance to appear on the homepage, the widget appears as expected.
I have removed this instance and am now trying to create the widget by going to content->pages
, editing the homepage -> content
section, and selecting insert widget
. I created a new instance of the widget and added some additional text
into the homepage -> content
section.
When I load the homepage the widget does not appear, though the rest of the text
does appear.
The block for the widget is being called ( I tested this with a var_dump
and exit
).
The template is not being rendered however.
Here is my Block:
<?php
namespace MyNamespace\Slider\Block\Widget;
use Magento\Framework\View\Element\Template;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\Catalog\Block\Product\Context;
class Slider extends Template
{
protected $_template = "Yamazaki_Slider::widget/slider.phtml";
/**
* @var CollectionFactory
*/
protected $_productCollectionFactory;
/**
* @var CollectionFactory
*/
protected $_imageHelper;
/**
* @param Context $context
* @param CollectionFactory $productCollectionFactory
*/
public function __construct(Context $context, CollectionFactory $productCollectionFactory)
{
$this->_imageHelper = $context->getImageHelper();
$this->_productCollectionFactory = $productCollectionFactory;
parent::__construct($context);
}
/**
* Retrieve featured products collection
*/
public function getProducts()
{
$collection = $this->_productCollectionFactory->create();
return $collection->addAttributeToSelect('*')->addAttributeToFilter('is_featured','1');
}
}
and my Template:
<?php $imageBlock = $block->getLayout()->createBlock('Magento\Catalog\Block\Product\ListProduct'); ?>
<?php foreach($this->getProducts() as $product): ?>
<?php $productImage = $imageBlock->getImage($product, 'product_page_image_large'); ?>
<?php echo $productImage->toHtml(); ?>
<?php endforeach ?>
Update
If I "Hide the Editor" inside content->pages->edit->content
I see:
<p>{{widget type="MyNamespace\Slider\Block\Widget\Slider"}}</p>`
If I replace this with
{{block class="MyNamespace\Slider\Block\Widget\Slider" template="widget/slider.phtml"}}
The Content appears as expected