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.

Jarnail S
4,70730 gold badges47 silver badges80 bronze badges
asked Jul 24, 2017 at 6:46
1
  • 1
    Your blockContent.phtml file should be placed at app/code/Funky/Hello/view/frontend/templates/blockContent.phtml Commented Jul 24, 2017 at 7:01

1 Answer 1

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.

Giel Berkers
12.4k7 gold badges80 silver badges125 bronze badges
answered Jul 24, 2017 at 9:50
1
  • 1
    layout folder does not content template files Commented Jul 24, 2017 at 14:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.