Hi I started larning Magento 2.3
I am developping an extension "Knc_Tips"
now menu is working, controller is fine maybe.
but, view file does not work. browser does not says any error but controller can not reach the view file I put.
etc/adminhtml/routes.xml
<router id="admin">
<route frontName="topic" id="topic">
<module name="Knc_Tips"/>
</route>
</router>
Controller/Adminhtml/Posts/Index.php
public function execute()
{
$resultPage = $this->pageFactory->create();
$resultPage->getConfig()->getTitle()->prepend((__('Posts')));
return $resultPage;
}view/adminhtml/layout/topic_posts_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head<
<title>
Posts
</title>
</head>
<body>
<div>test</div>
<referenceContainer name="content">
<block class="Magento\Backend\Block\Template" template="Knc_Tips::posts.phtml" />
</referenceContainer>
</body>
</page>
I put some html contents on topic_posts_index.xml but nothing come out on browser.
although there is resource container "posts.phtml", this also does not come up.
when I access this page, there is a page title "Posts" only. I think this is from Controller.
I thought Controller does not read the template file, so I changed the template file name to
view/adminhtml/layout/test.xml
i did cache clean, but still display does not change. not 404. just says page title "Posts".
I believe "Controller does not reach the layout file"
where do i have to check and pay attension to solve this problem?
Solved! Go to Solution.
So you have error in your layout (XML) file code, first is you have added <Head> tag wrong - check the syntax it is added like this - <head<
So it will not work here, put the following content in your view/adminhtml/layout/topic_posts_index.xml file
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<referenceBlock name="page.title">
<action method="setPageTitle">
<argument name="title" xsi:type="string">Posts</argument>
</action>
</referenceBlock>
<body>
<referenceContainer name="content">
<block class="Magento\Backend\Block\Template" template="Knc_Tips::posts.phtml"/>
</referenceContainer>
</body>
</page>
Second, you need to create the template file as well, (PHTML File) wherein you can put your content which will load the template.
Create posts.phtml file in this location - view/adminhtml/templates/posts.html - Adding following content it it :
<p>My First Posts load from template</p>
Now run all the necessary commands again like setup:upgrade, compile and static content deploy then clear and flush cache and check!
It will work for you.
Kindly refer below link:
https://devdocs.magento.com/guides/v2.4/ext-best-practices/extension-coding/example-module-adminpage...
In my case I have followed suggested steps and it works for me.
It may help you!
Problem Solved? Please click on 'Kudos' & Accept as Solution!
So you have error in your layout (XML) file code, first is you have added <Head> tag wrong - check the syntax it is added like this - <head<
So it will not work here, put the following content in your view/adminhtml/layout/topic_posts_index.xml file
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<referenceBlock name="page.title">
<action method="setPageTitle">
<argument name="title" xsi:type="string">Posts</argument>
</action>
</referenceBlock>
<body>
<referenceContainer name="content">
<block class="Magento\Backend\Block\Template" template="Knc_Tips::posts.phtml"/>
</referenceContainer>
</body>
</page>
Second, you need to create the template file as well, (PHTML File) wherein you can put your content which will load the template.
Create posts.phtml file in this location - view/adminhtml/templates/posts.html - Adding following content it it :
<p>My First Posts load from template</p>
Now run all the necessary commands again like setup:upgrade, compile and static content deploy then clear and flush cache and check!
It will work for you.
Hello @reikokurose240
Glad to know that it works for you.
Happy to help and keep helping others ![]()