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?

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.

| improve this answer | |
  • 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 Mar 31 at 9:22
  • please check my updated answer and update me – Msquare Mar 31 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 – Jackridder Mar 31 at 10:03
  • have you do all change of my above change ? – Msquare Mar 31 at 10:07
  • run magento command and check it – Msquare Mar 31 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.