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

asked Jan 17, 2018 at 12:20

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>
answered Jan 17, 2018 at 12:28
9
  • what will be path of Helloworld.php ? Commented Jan 17, 2018 at 12:33
  • And where its getting that block which I made on admin side? 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 ? Commented Jan 17, 2018 at 12:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.