I want to add a html page (which I made using code). How can I assign this 'test.phtml' file to a block named 'custom_block'. what is best way to do that ? any help would be highly appreciated. thank you
1 Answer
Create Helloworld.php
<?php
namespace Vendor\Module\Block;
class Helloworld extends \Magento\Framework\View\Element\Template
{
public function getTitle()
{
return 'Magento';
}
}
Call in layout xml
<referenceContainer name="
<block class="Vendor\Module\Block\Helloworld" name="helloworld" template="helloworld.phtml" />
</referenceContainer>
Call layout in phtml helloworld.phtml
<h1><?php echo $this->getTitle(); ?></h1>
-
-
And where its getting that block which I made on admin side?– LearnerCommented Jan 17, 2018 at 12:38
-
if admin block then use Vendor\Module\Block\Adminhtml like in Block/Adminhtml/Helloworld.php folder Commented Jan 17, 2018 at 12:46
-
-