0

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?

Msquare
9,4627 gold badges30 silver badges71 bronze badges
asked Mar 27, 2020 at 14:35

1 Answer 1

0

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.

answered Mar 27, 2020 at 15:29
14
  • 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? Commented Mar 31, 2020 at 9:22
  • please check my updated answer and update me Commented 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.x Commented Mar 31, 2020 at 10:03
  • have you do all change of my above change ? Commented Mar 31, 2020 at 10:07
  • run magento command and check it Commented Mar 31, 2020 at 10:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.