I am working to create custom widget in custom extension. I followed this to create widget in my custom extension.
All working fine but data not showing in the template
$this->setTemplate('widget/viewed_list.phtml');
Below my code:
Technologymindz/Instagramfeed/Block/Widget/Instawidget.php
<?php
namespace Technologymindz\Instagramfeed\Block\Widget;
class Instawidget extends \Magento\Framework\View\Element\Template implements \Magento\Widget\Block\BlockInterface
{
public function _toHtml()
{
$this->setTemplate('widget/viewed_list.phtml');
}
}
Technologymindz/Instagramfeed/etc/widget.xml
<?xml version="1.0" encoding="UTF-8"?>
<widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Magento/Widget/etc/widget.xsd">
<widget id="tm_customwidget" class="Technologymindz\Instagramfeed\Block\Widget\Instawidget">
<label translate="true">Instagram Feeds</label>
<description>Show Your Instagram Feeds Anywhere</description>
<parameters>
<parameter name="tmfeedtoshow" xsi:type="select" required="true" visible="true">
<label>Show Latest Feeds</label>
<options>
<option name="default" value="12" selected="true">
<label translate="true">12</label>
</option>
<option name="list" value="24">
<label translate="true">24</label>
</option>
</options>
</parameter>
<parameter name="tmview_type" xsi:type="select" required="true" visible="true">
<label>Select View Type</label>
<options>
<option name="default" value="widget/viewed_grid.phtml" selected="true">
<label translate="true">Grid View</label>
</option>
<option name="list" value="widget/viewed_list.phtml">
<label translate="true">List View</label>
</option>
</options>
</parameter>
</parameters>
</widget>
</widgets>
Technologymindz/Instagramfeed/view/frontend/widget/viewed_list.phtml
<?php
echo $this->getTmview_type();
echo 'Welcome';
?>
Data output not showing for viewed_list.phtml
but if i set something in Block _toHtml()
function than it shows.
public function _toHtml()
{
return '<p class="hello">Hello world!</p>';
}
Hope this is clear, I want to manage output in .phtml
not in Block