I created a custom route which is working fine. However it is just a blank page.

How can I add the header and the footer?


  • Can you explain in detail and also check magento mode, be sure it is developer – Devidas Jul 18 '18 at 13:40
  • As I said I created a custom route. When I call it it is just a blank page. So I want to add the header and footer like on other sites. – k33n Jul 18 '18 at 13:41
  • check magento mode, be sure it is developer mode. use this comand to check mode php bin/magento deploy:mode:show – Devidas Jul 18 '18 at 13:48

First we will create a helloworld_index_index.xml file in the app/code///view/frontend/layout folder with the following code:

<?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">
        <referenceContainer name="content">
            <block class="<vendor>\<Module>\Block\Index" name="helloworld.index" template="helloworld.phtml" />

create the Index.php controller file in the app/code///Controller/Index folder with the following code:


namespace <vendor>\<Module>\Controller\Index;

use Magento\Framework\App\Action\Context;

class Index extends \Magento\Framework\App\Action\Action
    protected $_resultPageFactory;

    public function __construct(Context $context, \Magento\Framework\View\Result\PageFactory $resultPageFactory)
        $this->_resultPageFactory = $resultPageFactory;

    public function execute()
        $resultPage = $this->_resultPageFactory->create();
        return $resultPage;

Create a Index.php file in the app/code///Block folder with the following code:

namespace <Vendor>\<Module>\Block;

class Index extends \Magento\Framework\View\Element\Template
    public function getHelloWorldTxt()
        return 'Hello world!';

Create a helloworld.phtml file in the app/code//view/frontend/templates folder with the following code:

<h1><?php echo $this->getHelloWorldTxt(); ?></h1>

After that clear cache and check.

  • can you tell me the layout files name for this route? <?xml version="1.0"?> <config xmlns:xsi="w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd"> <router id="standard"> <route id="newsletter_anmeldung" frontName="newsletter_anmeldung"> <module name="UO_NewsletterUV" /> </route> </router> </config> – k33n Jul 18 '18 at 14:22
  • Please create layout file like < newsletter_anmeldung_index_index.xml> in your layout folder – Dharmendra Jadav Jul 18 '18 at 14:24

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.