cancel
Showing results for 
Search instead for 
Did you mean: 

How to load a phtml from model function

How to load a phtml from model function

Hello,

In the magento2 I would like to call a phtml template from a Model Function

 

I I then create a new block in my module (My/Module/Block/Options/Type/Customview/File.php)

<?php
namespace My\Module\Block\Options\Type\Customview;

class File extends \Magento\Framework\View\Element\Template
{
    protected $_template = 'My_Module::options/type/customview/file.phtml';
 
}


I then tried calling this block from the model function  but do not manage...

I tried both :

$customizeBlock = new \My\Module\Block\Options\Type\Customview\File();

and

$customizeBlock = $this->_blockFactory->createBlock('My\Module\Block\Options\Type\Customview\file');


with no success...

 

What is the good way to make this call?

 

Thank you for your help,

 

Alex