I created a custom block and was able to link to it on the home page or display it there. Unfortunately I don't get the block displayed on another page I created via the backend. If I understand the whole thing correctly, do I have to change the name of the .xml created in the layout? This is how it works: enter image description here
and that's how it doesn't work: enter image description here
Do you have any idea how I can get the second case working?
1 Answer 1
First you have to Know about how layout file name should make.
cms_index_index.xml
Here
cms is route name
index is controller name
index is controller action file name
Replace your required route and controller file.
Update
app/code/VendoreName/ModuleName/Controller/Index
Index.php
<?php
namespace VendoreName\ModuleName\Controller\Index;
use Magento\Framework\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\App\Action\Action;
class Index extends Action implements HttpGetActionInterface, HttpPostActionInterface
{
/**
* @var PageFactory
*/
protected $resultPageFactory;
/**
* @param Context $context
* @param PageFactory $resultPageFactory
*/
public function __construct(
Context $context,
PageFactory $resultPageFactory
) {
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
}
/**
* Default customer account page
*
* @return \Magento\Framework\View\Result\Page
*/
public function execute()
{
echo "hellow";
exit();
//return $this->resultPageFactory->create();
}
}
app/code/VendoreName/ModuleName/view/frontend/layout
summary_index_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="page.main.title">
<action method="setPageTitle">
<argument translate="true" name="title" xsi:type="string">Summary Page</argument>
</action>
</referenceBlock>
<referenceContainer name="content">
</referenceContainer>
</body>
</page>
app/code/VendoreName/ModuleName/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="summary" id="summary">
<module name="VendoreName_ModuleName"/>
</route>
</router>
</config>
Now run Magento command
php bin/magento s:up
php bin/magento s:s:d -f
php bin/magento c:c
php bin/magento c:f
and Clear your browser cache
url like : domain/summary
I Hope This Helps You.
-
Many thanks for the answer. I have tried it and it also works with the URL: cms/index/summary But there is neither the layout nor the rest of the content of the summary page. My goal would be that it is located within the cms page "summary", i.e. callable with the following URL: domain/summary and there as a block as additional content. Could you help me with that?Jackridder– Jackridder2020年03月31日 09:22:09 +00:00Commented Mar 31, 2020 at 9:22
-
please check my updated answer and update meMsquare– Msquare2020年03月31日 09:36:53 +00:00Commented Mar 31, 2020 at 9:36
-
Hello again, thank you for the quick answers! I tested it immediately and the message "hellow" only appears on the "domain/summary/index" page. Am I doing something wrong or what else do I have to do? I'm sorry for the many questions, but I can't get on with this x.xJackridder– Jackridder2020年03月31日 10:03:00 +00:00Commented Mar 31, 2020 at 10:03
-
have you do all change of my above change ?Msquare– Msquare2020年03月31日 10:07:27 +00:00Commented Mar 31, 2020 at 10:07
-
run magento command and check itMsquare– Msquare2020年03月31日 10:07:46 +00:00Commented Mar 31, 2020 at 10:07