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
Learner
8334 gold badges20 silver badges44 bronze badges
1 Answer 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
Birjitsinh Zala
1,1776 silver badges20 bronze badges
-
what will be path of Helloworld.php ?Learner– Learner2018年01月17日 12:33:52 +00:00Commented Jan 17, 2018 at 12:33
-
And where its getting that block which I made on admin side?Learner– Learner2018年01月17日 12:38:49 +00:00Commented Jan 17, 2018 at 12:38
-
if admin block then use Vendor\Module\Block\Adminhtml like in Block/Adminhtml/Helloworld.php folderBirjitsinh Zala– Birjitsinh Zala2018年01月17日 12:46:41 +00:00Commented Jan 17, 2018 at 12:46
-
get in view/adminhtml/templates/helloword.phtmlBirjitsinh Zala– Birjitsinh Zala2018年01月17日 12:49:12 +00:00Commented Jan 17, 2018 at 12:49
-
okay and what will path of xml and helloworld.phtml ?Learner– Learner2018年01月17日 12:50:00 +00:00Commented Jan 17, 2018 at 12:50
Explore related questions
See similar questions with these tags.
default