Here is the routes.xml file

<?xml version="1.0"?>
* Copyright © 2017 Magento. All rights reserved.
* See COPYING.txt for license details.
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
    <route id="unit3helloworldblock" frontName="unit3helloworldblock">
        <module name="Unit3_HelloWorldBlock" />

In Unit3\HelloWorldBlock\Controller\Block there is this Index.php file

 * Class Index
 * @package Unit3\HelloWorldBlock\Controller\Block
class Index extends \Magento\Framework\App\Action\Action
protected $_pageFactory;

public function __construct(
    \Magento\Framework\App\Action\Context $context,
    \Magento\Framework\View\Result\PageFactory $pageFactory
) {
    $this->_pageFactory = $pageFactory;

 * return result
public function execute()
    $layout = $this->_pageFactory->create()->getLayout();
    $block = $layout->createBlock('Unit3\HelloWorldBlock\Block\Test');
    $result = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW);
    return $result;

I have attempted




I have checked to make sure the module is enabled, ran upgrade, compiled, flushed cache, and removed generated.



Your url should be formed like this: unit3helloworldblock/block/index (or even unit3helloworldblock/block since your controller name is Index)


The url to your controller is formed according to the follow pattern: <front-name>/<controller-name>/<action-name>


This is the front-name you defined in the routes.xml


This is your folder structure. The router is already going to look inside your Controller folder from your module.

Bear mind if you have multiple levels inside your controller folder. 'Controller/Block/Frontend/Index', your controller name is 'block_frontend;.


This is the name of your controller action.

You can find more information here: https://devdocs.magento.com/guides/v2.3/extension-dev-guide/routing.html

| improve this answer | |

The url is built according this pattern:


If the action is called Index that part must not be used. Therefore for your controller called Block and the action Index the url should be:


If your controller is called Index (directory) you can use just the frontname for your url:

| improve this answer | |

Your URL into this case is,




| improve this answer | |

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.