Magento 2: Why block initialized but template not rendered?
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 VendorTestControllerExec;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkAppResponseInterface;
class Bank extends MagentoFrameworkAppActionAction
{
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="VendorTestBlockDate" name="vendor.test.date" template="date.phtml" >
<arguments>
<argument name="something" xsi:type="string">Value</argument>
</arguments>
</block>
</body>
</page>
My Block:
<?php
namespace VendorTestBlock;
class Date extends MagentoFrameworkViewElementTemplate
{
/**
* @param MagentoFrameworkViewElementTemplateContext $context
* @param array $data
*/
public function __construct(MagentoFrameworkViewElementTemplateContext $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:
magento2 layout blocks template xml
add a comment |
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 VendorTestControllerExec;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkAppResponseInterface;
class Bank extends MagentoFrameworkAppActionAction
{
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="VendorTestBlockDate" name="vendor.test.date" template="date.phtml" >
<arguments>
<argument name="something" xsi:type="string">Value</argument>
</arguments>
</block>
</body>
</page>
My Block:
<?php
namespace VendorTestBlock;
class Date extends MagentoFrameworkViewElementTemplate
{
/**
* @param MagentoFrameworkViewElementTemplateContext $context
* @param array $data
*/
public function __construct(MagentoFrameworkViewElementTemplateContext $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:
magento2 layout blocks template xml
add a comment |
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 VendorTestControllerExec;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkAppResponseInterface;
class Bank extends MagentoFrameworkAppActionAction
{
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="VendorTestBlockDate" name="vendor.test.date" template="date.phtml" >
<arguments>
<argument name="something" xsi:type="string">Value</argument>
</arguments>
</block>
</body>
</page>
My Block:
<?php
namespace VendorTestBlock;
class Date extends MagentoFrameworkViewElementTemplate
{
/**
* @param MagentoFrameworkViewElementTemplateContext $context
* @param array $data
*/
public function __construct(MagentoFrameworkViewElementTemplateContext $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:
magento2 layout blocks template xml
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 VendorTestControllerExec;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkAppResponseInterface;
class Bank extends MagentoFrameworkAppActionAction
{
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="VendorTestBlockDate" name="vendor.test.date" template="date.phtml" >
<arguments>
<argument name="something" xsi:type="string">Value</argument>
</arguments>
</block>
</body>
</page>
My Block:
<?php
namespace VendorTestBlock;
class Date extends MagentoFrameworkViewElementTemplate
{
/**
* @param MagentoFrameworkViewElementTemplateContext $context
* @param array $data
*/
public function __construct(MagentoFrameworkViewElementTemplateContext $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:
magento2 layout blocks template xml
magento2 layout blocks template xml
edited May 28 '17 at 12:16
Rafael Corrêa Gomes
4,53423264
4,53423264
asked May 27 '17 at 22:30
undoneundone
2061218
2061218
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Change your layout file by following code
<?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>Bank Page Title</title>
</head>
<body>
<referenceContainer name="content">
<block class="VendorTestBlockDate" name="vendor.test.date" template="Vendor_Test::date.phtml">
<arguments>
<argument name="something" xsi:type="string">Value</argument>
</arguments>
</block>
</referenceContainer>
</body>
</page>
Clear cache.
It worked! Can you point to me where was the problem? using3column
? not usingreferenceContainer
?
– undone
May 28 '17 at 12:15
Check <referenceContainer name="content">
– Sohel Rana
May 28 '17 at 13:01
Read more devdocs.magento.com/guides/v2.1/frontend-dev-guide/layouts/…
– Sohel Rana
May 28 '17 at 13:01
add a comment |
In my case, I had some function calls in my template file. As one of the functions which were throwing some error. That was causing the template file from not rendering. So, anything after that function call will not display.
New contributor
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f176348%2fmagento-2-why-block-initialized-but-template-not-rendered%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Change your layout file by following code
<?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>Bank Page Title</title>
</head>
<body>
<referenceContainer name="content">
<block class="VendorTestBlockDate" name="vendor.test.date" template="Vendor_Test::date.phtml">
<arguments>
<argument name="something" xsi:type="string">Value</argument>
</arguments>
</block>
</referenceContainer>
</body>
</page>
Clear cache.
It worked! Can you point to me where was the problem? using3column
? not usingreferenceContainer
?
– undone
May 28 '17 at 12:15
Check <referenceContainer name="content">
– Sohel Rana
May 28 '17 at 13:01
Read more devdocs.magento.com/guides/v2.1/frontend-dev-guide/layouts/…
– Sohel Rana
May 28 '17 at 13:01
add a comment |
Change your layout file by following code
<?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>Bank Page Title</title>
</head>
<body>
<referenceContainer name="content">
<block class="VendorTestBlockDate" name="vendor.test.date" template="Vendor_Test::date.phtml">
<arguments>
<argument name="something" xsi:type="string">Value</argument>
</arguments>
</block>
</referenceContainer>
</body>
</page>
Clear cache.
It worked! Can you point to me where was the problem? using3column
? not usingreferenceContainer
?
– undone
May 28 '17 at 12:15
Check <referenceContainer name="content">
– Sohel Rana
May 28 '17 at 13:01
Read more devdocs.magento.com/guides/v2.1/frontend-dev-guide/layouts/…
– Sohel Rana
May 28 '17 at 13:01
add a comment |
Change your layout file by following code
<?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>Bank Page Title</title>
</head>
<body>
<referenceContainer name="content">
<block class="VendorTestBlockDate" name="vendor.test.date" template="Vendor_Test::date.phtml">
<arguments>
<argument name="something" xsi:type="string">Value</argument>
</arguments>
</block>
</referenceContainer>
</body>
</page>
Clear cache.
Change your layout file by following code
<?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>Bank Page Title</title>
</head>
<body>
<referenceContainer name="content">
<block class="VendorTestBlockDate" name="vendor.test.date" template="Vendor_Test::date.phtml">
<arguments>
<argument name="something" xsi:type="string">Value</argument>
</arguments>
</block>
</referenceContainer>
</body>
</page>
Clear cache.
answered May 28 '17 at 7:05
Sohel RanaSohel Rana
22.4k34460
22.4k34460
It worked! Can you point to me where was the problem? using3column
? not usingreferenceContainer
?
– undone
May 28 '17 at 12:15
Check <referenceContainer name="content">
– Sohel Rana
May 28 '17 at 13:01
Read more devdocs.magento.com/guides/v2.1/frontend-dev-guide/layouts/…
– Sohel Rana
May 28 '17 at 13:01
add a comment |
It worked! Can you point to me where was the problem? using3column
? not usingreferenceContainer
?
– undone
May 28 '17 at 12:15
Check <referenceContainer name="content">
– Sohel Rana
May 28 '17 at 13:01
Read more devdocs.magento.com/guides/v2.1/frontend-dev-guide/layouts/…
– Sohel Rana
May 28 '17 at 13:01
It worked! Can you point to me where was the problem? using
3column
? not using referenceContainer
?– undone
May 28 '17 at 12:15
It worked! Can you point to me where was the problem? using
3column
? not using referenceContainer
?– undone
May 28 '17 at 12:15
Check <referenceContainer name="content">
– Sohel Rana
May 28 '17 at 13:01
Check <referenceContainer name="content">
– Sohel Rana
May 28 '17 at 13:01
Read more devdocs.magento.com/guides/v2.1/frontend-dev-guide/layouts/…
– Sohel Rana
May 28 '17 at 13:01
Read more devdocs.magento.com/guides/v2.1/frontend-dev-guide/layouts/…
– Sohel Rana
May 28 '17 at 13:01
add a comment |
In my case, I had some function calls in my template file. As one of the functions which were throwing some error. That was causing the template file from not rendering. So, anything after that function call will not display.
New contributor
add a comment |
In my case, I had some function calls in my template file. As one of the functions which were throwing some error. That was causing the template file from not rendering. So, anything after that function call will not display.
New contributor
add a comment |
In my case, I had some function calls in my template file. As one of the functions which were throwing some error. That was causing the template file from not rendering. So, anything after that function call will not display.
New contributor
In my case, I had some function calls in my template file. As one of the functions which were throwing some error. That was causing the template file from not rendering. So, anything after that function call will not display.
New contributor
New contributor
answered 4 mins ago
hardik thakkarhardik thakkar
1
1
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f176348%2fmagento-2-why-block-initialized-but-template-not-rendered%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown