I have a page that I want to add content to it. My problem is that my block is initialized and setTemplate
is called but my template never rendered. I tried adding module name to layout (Vendor_Test::
) but it made no difference. When I edit my layout, I change the title and clean the cache, so I can see that new title is applied.
Here is my files:
Controller:
<?php
namespace Vendor\Test\Controller\Exec;
use Magento\Framework\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
use Magento\Framework\App\ResponseInterface;
class Bank extends \Magento\Framework\App\Action\Action
{
protected $resultPageFactory;
public function __construct(
Context $context,
PageFactory $resultPageFactory
)
{
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
}
public function execute()
{
$page = $this->resultPageFactory->create();
return $page;
}
}
My layout:
<?xml version="1.0"?>
<page layout="3column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<title>Bank Page Title</title>
</head>
<body>
<block class="Vendor\Test\Block\Date" name="vendor.test.date" template="date.phtml" >
<arguments>
<argument name="something" xsi:type="string">Value</argument>
</arguments>
</block>
</body>
</page>
My Block:
<?php
namespace Vendor\Test\Block;
class Date extends \Magento\Framework\View\Element\Template
{
/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param array $data
*/
public function __construct(\Magento\Framework\View\Element\Template\Context $context, array $data = [])
{
parent::__construct($context, $data);
}
public function getDate()
{
return date('m/d/Y H:i:s');
}
}
My template:
<div class="Something" >
<?php echo $block->getDate();?>
</div>
Output: