Magento does not read phtml file
I'm absolute newbie at magento2.
My code:
Block/Index.php
<?php
namespace VendorModuleBlock;
class Index extends MagentoFrameworkViewElementTemplate
{
}
Controller/Index.php
<?php
namespace VendorModuleControllerIndex;
class Index extends MagentoFrameworkAppActionAction
{
protected $_pageFactory;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkViewResultPageFactory $pageFactory)
{
$this->_pageFactory = $pageFactory;
return parent::__construct($context);
}
public function execute()
{
return $this->_pageFactory->create();
}
}
Vendor/Module/etc/frontend/routes.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route frontName="helloworld" id="helloworld">
<module name="Vendor_Module"/>
</route>
</router>
</config>
etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_Module" setup_version="1.0.0">
</module>
</config>
Vendor/Module/view/frontend/template/index/index.phtml
<h2>Helloworld</h2>
Vendor/Module/view/layout/helloworld_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">
<referenceContainer name="content">
<block class="VendorModuleBlockIndex" name="index.index" template="Vendor_Module::index/index.phtml"/>
</referenceContainer>
</page>
Unfortunately
Helloworld
is not displaying.Any suggestions?
magento2
New contributor
add a comment |
I'm absolute newbie at magento2.
My code:
Block/Index.php
<?php
namespace VendorModuleBlock;
class Index extends MagentoFrameworkViewElementTemplate
{
}
Controller/Index.php
<?php
namespace VendorModuleControllerIndex;
class Index extends MagentoFrameworkAppActionAction
{
protected $_pageFactory;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkViewResultPageFactory $pageFactory)
{
$this->_pageFactory = $pageFactory;
return parent::__construct($context);
}
public function execute()
{
return $this->_pageFactory->create();
}
}
Vendor/Module/etc/frontend/routes.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route frontName="helloworld" id="helloworld">
<module name="Vendor_Module"/>
</route>
</router>
</config>
etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_Module" setup_version="1.0.0">
</module>
</config>
Vendor/Module/view/frontend/template/index/index.phtml
<h2>Helloworld</h2>
Vendor/Module/view/layout/helloworld_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">
<referenceContainer name="content">
<block class="VendorModuleBlockIndex" name="index.index" template="Vendor_Module::index/index.phtml"/>
</referenceContainer>
</page>
Unfortunately
Helloworld
is not displaying.Any suggestions?
magento2
New contributor
Can you send from which url are you trying to access page ? Also Vendor/Module/view/frontend/template/index.php file should be .phtml
– user55548
16 hours ago
1
Where is the layout.xml it should be helloworld_index_index.xml
– G Prathap
16 hours ago
add a comment |
I'm absolute newbie at magento2.
My code:
Block/Index.php
<?php
namespace VendorModuleBlock;
class Index extends MagentoFrameworkViewElementTemplate
{
}
Controller/Index.php
<?php
namespace VendorModuleControllerIndex;
class Index extends MagentoFrameworkAppActionAction
{
protected $_pageFactory;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkViewResultPageFactory $pageFactory)
{
$this->_pageFactory = $pageFactory;
return parent::__construct($context);
}
public function execute()
{
return $this->_pageFactory->create();
}
}
Vendor/Module/etc/frontend/routes.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route frontName="helloworld" id="helloworld">
<module name="Vendor_Module"/>
</route>
</router>
</config>
etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_Module" setup_version="1.0.0">
</module>
</config>
Vendor/Module/view/frontend/template/index/index.phtml
<h2>Helloworld</h2>
Vendor/Module/view/layout/helloworld_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">
<referenceContainer name="content">
<block class="VendorModuleBlockIndex" name="index.index" template="Vendor_Module::index/index.phtml"/>
</referenceContainer>
</page>
Unfortunately
Helloworld
is not displaying.Any suggestions?
magento2
New contributor
I'm absolute newbie at magento2.
My code:
Block/Index.php
<?php
namespace VendorModuleBlock;
class Index extends MagentoFrameworkViewElementTemplate
{
}
Controller/Index.php
<?php
namespace VendorModuleControllerIndex;
class Index extends MagentoFrameworkAppActionAction
{
protected $_pageFactory;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkViewResultPageFactory $pageFactory)
{
$this->_pageFactory = $pageFactory;
return parent::__construct($context);
}
public function execute()
{
return $this->_pageFactory->create();
}
}
Vendor/Module/etc/frontend/routes.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route frontName="helloworld" id="helloworld">
<module name="Vendor_Module"/>
</route>
</router>
</config>
etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_Module" setup_version="1.0.0">
</module>
</config>
Vendor/Module/view/frontend/template/index/index.phtml
<h2>Helloworld</h2>
Vendor/Module/view/layout/helloworld_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">
<referenceContainer name="content">
<block class="VendorModuleBlockIndex" name="index.index" template="Vendor_Module::index/index.phtml"/>
</referenceContainer>
</page>
Unfortunately
Helloworld
is not displaying.Any suggestions?
magento2
magento2
New contributor
New contributor
edited 14 hours ago
PЯINCƏ
8,03331141
8,03331141
New contributor
asked 16 hours ago
Rich FuRich Fu
324
324
New contributor
New contributor
Can you send from which url are you trying to access page ? Also Vendor/Module/view/frontend/template/index.php file should be .phtml
– user55548
16 hours ago
1
Where is the layout.xml it should be helloworld_index_index.xml
– G Prathap
16 hours ago
add a comment |
Can you send from which url are you trying to access page ? Also Vendor/Module/view/frontend/template/index.php file should be .phtml
– user55548
16 hours ago
1
Where is the layout.xml it should be helloworld_index_index.xml
– G Prathap
16 hours ago
Can you send from which url are you trying to access page ? Also Vendor/Module/view/frontend/template/index.php file should be .phtml
– user55548
16 hours ago
Can you send from which url are you trying to access page ? Also Vendor/Module/view/frontend/template/index.php file should be .phtml
– user55548
16 hours ago
1
1
Where is the layout.xml it should be helloworld_index_index.xml
– G Prathap
16 hours ago
Where is the layout.xml it should be helloworld_index_index.xml
– G Prathap
16 hours ago
add a comment |
3 Answers
3
active
oldest
votes
1/
Vendor/Module/view/frontend/templates/index/index.phtml
and not
Vendor/Module/view/frontend/template/index/index.phtml
note:
template
in Magento 1
templates
in Magento 2
2/
Vendor/Module/view/frontend/layout/helloworld_index_index.xml
and not
Vendor/Module/view/layout/helloworld_index_index.xml
add a comment |
I found 2 mistakes in the code
Vendor/Module/view/layout/helloworld_index_index.xml this should be in Vendor/Module/view/frontend/layout/helloworld_index_index.xml
Vendor/Module/view/frontend/template/index/index.phtml file this should be Vendor/Module/view/frontend/templates/index/index.phtml
Make above to changes and flush cache and then check
add a comment |
If you rename tha template file from index.php
to index.phtml
, move it to view/frontent/templates/index/
and add a layout xml file in view/frontend/layout/helloworld_index_index.xml
your code should work.
For example if you just want to output the content of your template in the content area, you can use the following xml layout:
<?xml version="1.0" ?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="MagentoFrameworkViewElementTemplate" name="index.index" template="Vendor_Module::index/index.phtml"/>
</referenceContainer>
</body>
</page>
For using your bock you need to replace MagentoFrameworkViewElementTemplate
with VendorModuleBlockIndex
in the layout xml.
I've done your suggested changes, but still no result and no errors as well... I have updated my code above.
– Rich Fu
15 hours ago
please check if you have enabled layout caching, if yes you have to flush that cache. But it would be better to deactivate it
– HelgeB
15 hours ago
There is a type in the template path, I updated my answer too - it must be "templates" not "template"
– HelgeB
14 hours ago
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
});
}
});
Rich Fu is a new contributor. Be nice, and check out our Code of Conduct.
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%2f262248%2fmagento-does-not-read-phtml-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
1/
Vendor/Module/view/frontend/templates/index/index.phtml
and not
Vendor/Module/view/frontend/template/index/index.phtml
note:
template
in Magento 1
templates
in Magento 2
2/
Vendor/Module/view/frontend/layout/helloworld_index_index.xml
and not
Vendor/Module/view/layout/helloworld_index_index.xml
add a comment |
1/
Vendor/Module/view/frontend/templates/index/index.phtml
and not
Vendor/Module/view/frontend/template/index/index.phtml
note:
template
in Magento 1
templates
in Magento 2
2/
Vendor/Module/view/frontend/layout/helloworld_index_index.xml
and not
Vendor/Module/view/layout/helloworld_index_index.xml
add a comment |
1/
Vendor/Module/view/frontend/templates/index/index.phtml
and not
Vendor/Module/view/frontend/template/index/index.phtml
note:
template
in Magento 1
templates
in Magento 2
2/
Vendor/Module/view/frontend/layout/helloworld_index_index.xml
and not
Vendor/Module/view/layout/helloworld_index_index.xml
1/
Vendor/Module/view/frontend/templates/index/index.phtml
and not
Vendor/Module/view/frontend/template/index/index.phtml
note:
template
in Magento 1
templates
in Magento 2
2/
Vendor/Module/view/frontend/layout/helloworld_index_index.xml
and not
Vendor/Module/view/layout/helloworld_index_index.xml
answered 14 hours ago
PЯINCƏPЯINCƏ
8,03331141
8,03331141
add a comment |
add a comment |
I found 2 mistakes in the code
Vendor/Module/view/layout/helloworld_index_index.xml this should be in Vendor/Module/view/frontend/layout/helloworld_index_index.xml
Vendor/Module/view/frontend/template/index/index.phtml file this should be Vendor/Module/view/frontend/templates/index/index.phtml
Make above to changes and flush cache and then check
add a comment |
I found 2 mistakes in the code
Vendor/Module/view/layout/helloworld_index_index.xml this should be in Vendor/Module/view/frontend/layout/helloworld_index_index.xml
Vendor/Module/view/frontend/template/index/index.phtml file this should be Vendor/Module/view/frontend/templates/index/index.phtml
Make above to changes and flush cache and then check
add a comment |
I found 2 mistakes in the code
Vendor/Module/view/layout/helloworld_index_index.xml this should be in Vendor/Module/view/frontend/layout/helloworld_index_index.xml
Vendor/Module/view/frontend/template/index/index.phtml file this should be Vendor/Module/view/frontend/templates/index/index.phtml
Make above to changes and flush cache and then check
I found 2 mistakes in the code
Vendor/Module/view/layout/helloworld_index_index.xml this should be in Vendor/Module/view/frontend/layout/helloworld_index_index.xml
Vendor/Module/view/frontend/template/index/index.phtml file this should be Vendor/Module/view/frontend/templates/index/index.phtml
Make above to changes and flush cache and then check
answered 15 hours ago
PMBPMB
372220
372220
add a comment |
add a comment |
If you rename tha template file from index.php
to index.phtml
, move it to view/frontent/templates/index/
and add a layout xml file in view/frontend/layout/helloworld_index_index.xml
your code should work.
For example if you just want to output the content of your template in the content area, you can use the following xml layout:
<?xml version="1.0" ?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="MagentoFrameworkViewElementTemplate" name="index.index" template="Vendor_Module::index/index.phtml"/>
</referenceContainer>
</body>
</page>
For using your bock you need to replace MagentoFrameworkViewElementTemplate
with VendorModuleBlockIndex
in the layout xml.
I've done your suggested changes, but still no result and no errors as well... I have updated my code above.
– Rich Fu
15 hours ago
please check if you have enabled layout caching, if yes you have to flush that cache. But it would be better to deactivate it
– HelgeB
15 hours ago
There is a type in the template path, I updated my answer too - it must be "templates" not "template"
– HelgeB
14 hours ago
add a comment |
If you rename tha template file from index.php
to index.phtml
, move it to view/frontent/templates/index/
and add a layout xml file in view/frontend/layout/helloworld_index_index.xml
your code should work.
For example if you just want to output the content of your template in the content area, you can use the following xml layout:
<?xml version="1.0" ?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="MagentoFrameworkViewElementTemplate" name="index.index" template="Vendor_Module::index/index.phtml"/>
</referenceContainer>
</body>
</page>
For using your bock you need to replace MagentoFrameworkViewElementTemplate
with VendorModuleBlockIndex
in the layout xml.
I've done your suggested changes, but still no result and no errors as well... I have updated my code above.
– Rich Fu
15 hours ago
please check if you have enabled layout caching, if yes you have to flush that cache. But it would be better to deactivate it
– HelgeB
15 hours ago
There is a type in the template path, I updated my answer too - it must be "templates" not "template"
– HelgeB
14 hours ago
add a comment |
If you rename tha template file from index.php
to index.phtml
, move it to view/frontent/templates/index/
and add a layout xml file in view/frontend/layout/helloworld_index_index.xml
your code should work.
For example if you just want to output the content of your template in the content area, you can use the following xml layout:
<?xml version="1.0" ?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="MagentoFrameworkViewElementTemplate" name="index.index" template="Vendor_Module::index/index.phtml"/>
</referenceContainer>
</body>
</page>
For using your bock you need to replace MagentoFrameworkViewElementTemplate
with VendorModuleBlockIndex
in the layout xml.
If you rename tha template file from index.php
to index.phtml
, move it to view/frontent/templates/index/
and add a layout xml file in view/frontend/layout/helloworld_index_index.xml
your code should work.
For example if you just want to output the content of your template in the content area, you can use the following xml layout:
<?xml version="1.0" ?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="MagentoFrameworkViewElementTemplate" name="index.index" template="Vendor_Module::index/index.phtml"/>
</referenceContainer>
</body>
</page>
For using your bock you need to replace MagentoFrameworkViewElementTemplate
with VendorModuleBlockIndex
in the layout xml.
edited 14 hours ago
answered 16 hours ago
HelgeBHelgeB
1,12214
1,12214
I've done your suggested changes, but still no result and no errors as well... I have updated my code above.
– Rich Fu
15 hours ago
please check if you have enabled layout caching, if yes you have to flush that cache. But it would be better to deactivate it
– HelgeB
15 hours ago
There is a type in the template path, I updated my answer too - it must be "templates" not "template"
– HelgeB
14 hours ago
add a comment |
I've done your suggested changes, but still no result and no errors as well... I have updated my code above.
– Rich Fu
15 hours ago
please check if you have enabled layout caching, if yes you have to flush that cache. But it would be better to deactivate it
– HelgeB
15 hours ago
There is a type in the template path, I updated my answer too - it must be "templates" not "template"
– HelgeB
14 hours ago
I've done your suggested changes, but still no result and no errors as well... I have updated my code above.
– Rich Fu
15 hours ago
I've done your suggested changes, but still no result and no errors as well... I have updated my code above.
– Rich Fu
15 hours ago
please check if you have enabled layout caching, if yes you have to flush that cache. But it would be better to deactivate it
– HelgeB
15 hours ago
please check if you have enabled layout caching, if yes you have to flush that cache. But it would be better to deactivate it
– HelgeB
15 hours ago
There is a type in the template path, I updated my answer too - it must be "templates" not "template"
– HelgeB
14 hours ago
There is a type in the template path, I updated my answer too - it must be "templates" not "template"
– HelgeB
14 hours ago
add a comment |
Rich Fu is a new contributor. Be nice, and check out our Code of Conduct.
Rich Fu is a new contributor. Be nice, and check out our Code of Conduct.
Rich Fu is a new contributor. Be nice, and check out our Code of Conduct.
Rich Fu is a new contributor. Be nice, and check out our Code of Conduct.
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%2f262248%2fmagento-does-not-read-phtml-file%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
Can you send from which url are you trying to access page ? Also Vendor/Module/view/frontend/template/index.php file should be .phtml
– user55548
16 hours ago
1
Where is the layout.xml it should be helloworld_index_index.xml
– G Prathap
16 hours ago