0

Hello I am new to Magento & using Magento 2.1.7. I was learning to develop custom module. My module is working till the controller but it is not printing the data present in the template file named blockContent.phtml.

My Code:

App/Code/Funky/Hello/Controller/Path/HelloWorld.php

<?php

namespace Funky\Hello\Controller\Path;

use \Magento\Framework\App\Action\Action;
use \Magento\Framework\App\ResponseInterface;
use \Magento\Framework\View\Result\PageFactory;
use \Magento\Framework\App\Action\Context;

class HelloWorld extends Action
{
    protected $pagefactory;
    public function __construct(Context  $context, PageFactory $pageFactory)
    {
        $this->pagefactory=$pageFactory;
        Parent::__construct($context);
    }
    /**
     * Dispatch request
     *
     * @return \Magento\Framework\Controller\ResultInterface|ResponseInterface
     * @throws \Magento\Framework\Exception\NotFoundException
     */
    public function execute()
    {
        echo "testing? is working";
        return $this->pagefactory->create();

    }
}

App/Code/Funky/Hello/Block/Main.php

<?php 
namespace Funky\Hello\Block;
use \Magento\Framework\View\Element\Template;

class Main extends Template
{
    public function _prepareLayout()
    {


    }

}

App/Code/Funky/Hello/etc/frontend/route.xml

<?xml version="1.0"  ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation=
        "urn:magento:framework:Module/etc/routes.xsd">
    <router id="standard">
        <route id="funky" frontName="funky">
            <module name="Funky_Hello"/>
        </route>
    </router>
</config>

App/Code/Funky/Hello/etc/module.xml

<?xml version="1.0"  ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation=
        "urn:magento:framework:Module/etc/module.xsd">
    <module name="Funky_Hello" setup_version="0.0.1"/>
</config>

App/Code/Funky/Hello/view/frontend/layout/funky_path_helloworld.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation=
        "urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="columns.top">
            <block class="Funky\Hello\Block\Main"
                   template="workin.phtml"
                   name="funky_hello_Hell"/>
        </referenceContainer>
        <referenceContainer name="content">
                <block class="Funky\Hello\Block\Main"
                       template="Funky_Hello::blockContent.phtml"
                       name="funky_hello_HelloWorld"/>
        </referenceContainer>

    </body>
</page>

App/Code/Funky/Hello/view/frontend/layout/templates/blockContent.phtml

<b>Hello World!</b>

<h1>It is working or not???</h1>


<?php echo "nothing is happening why? ";?>

I have also created the registration.php. If any one can tell me what exactly I am doing mistake? Thank you in advance.

  • 1
    Your blockContent.phtml file should be placed at app/code/Funky/Hello/view/frontend/templates/blockContent.phtml – Quan Le Jul 24 '17 at 7:01
2

Change the file path to

App/Code/Funky/Hello/view/frontend/templates/blockContent.phtml

instead of

App/Code/Funky/Hello/view/frontend/layout/templates/blockContent.phtml

In a layout folder there are always xml files.

  • 1
    layout folder does not content template files – Murtuza Zabuawala Jul 24 '17 at 14:32

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.