A template block with configuration

Step 1
Create Block File: $MAGENTO_DIR/app/code/Imran/Test/Block/Titles.php

<?php
namespace Imran\Test\Block;
 
class Titles extends \Magento\Framework\View\Element\Template
{
    public function getTitle()
    {
        return "Mr";
    }
}

Step 2
Create Layout File: $MAGENTO_DIR/app/code/Imran/Test/view/layout/test_index_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <title/>
    </head>
    <body>
        <referenceContainer name="content">
            <block class="Imran\Test\Block\Tiles" template="Imran_Test::landingpage.phtml"/>
        </referenceContainer>
        <referenceBlock name="test-block" remove="true"/>
    </body>
</page>

Step 3
Create Template phtml File: $MAGENTO_DIR/app/code/Imran/Test/view/templates/landingpage.phtml

<?php
echo $this->getTitle();
?>

Leave a Reply