0

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 1

1

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>
9
  • what will be path of Helloworld.php ?
    – Learner
    Commented Jan 17, 2018 at 12:33
  • And where its getting that block which I made on admin side?
    – Learner
    Commented 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
  • get in view/adminhtml/templates/helloword.phtml Commented Jan 17, 2018 at 12:49
  • okay and what will path of xml and helloworld.phtml ?
    – Learner
    Commented Jan 17, 2018 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.