Skip to content

Latest commit

 

History

History
105 lines (69 loc) · 2.91 KB

3.show-header-footer-on-frontend-url.md

File metadata and controls

105 lines (69 loc) · 2.91 KB

Show header& footer and content Section:

Required file:

  • app/code/{Vendor}/{ModuleName}/Controller/ControllerFolderInCamalCaseLetter/ActionFileNameInCamalCaseLetter.php(Modified)
  • app/code/{Vendor}/{ModuleName}/view/frontend/layout/{RouteIdSmallLetter}_{ControllerFolderInSmallLetter}_{ActioNameInSmall}.xml

Study Link

https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/layouts/layout-overview.html

Modify Action file Action file

app/code/{Vendor}/{ModuleName}/Controller/ControllerFolderInCamalCaseLetter/ActionFileNameInCamalCaseLetter.php

<?php

namespace {Vendor}\{ModuleName}\Controller\ControllerFolderInCamalCaseLetter;

use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
use Magento\Framework\Controller\ResultFactory;

class ActionFileNameInCamalCaseLetter extends \Magento\Framework\App\Action\Action implements HttpGetActionInterface
{
    
    public function __construct(
            \Magento\Framework\App\Action\Context $context
     ) {
        parent::__construct($context);
    }

    public function execute() 
    {
       return $this->resultFactory->create(ResultFactory::TYPE_PAGE);
    }

}

Example

  • File Path: app/code/StackExchange/Example/Controller/Index/Index.php
<?php

namespace StackExchange\Example\Controller\Index;

use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
use Magento\Framework\Controller\ResultFactory;

class Index extends \Magento\Framework\App\Action\Action implements HttpGetActionInterface
{
    
    public function __construct(
            \Magento\Framework\App\Action\Context $context
     ) {
        parent::__construct($context);
    }

    public function execute() 
    {
       return $this->resultFactory->create(ResultFactory::TYPE_PAGE);
    }

}

Add Layout files:

<?xml version="1.0" encoding="UTF-8"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <title>Your Page Title</title>
    </head>
</page>

Example files:

  • file name examples_index_index.xml**
<?xml version="1.0" encoding="UTF-8"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <title>Example Page</title>
    </head>
</page>

Your hit URL: http://domain.com/example/index/index: The response comming like this: