0

I've created a custom Magento 2 Module and I am facing a problem of URL returning blank page If I am calling the block from template file using layout

Magento Version : 2.2.4

URL Trying to visit : 127.0.0.1/magento/whatsapp/index/display

It returns a blank page.

here is my files structure:

Mahran/Whatsapp/Block/Display.php

<?php
namespace Mahran\Whatsapp\Block;
class Display extends \Magento\Framework\View\Element\Template
{
    public function __construct(\Magento\Framework\View\Element\Template\Context $context)
    {
        parent::__construct($context);
    }

    public function sayHello()
    {
        return __('Hello World');
    }
}

Mahran\Whatsapp\Controller\Index\Display.php

<?php

namespace Mahran\Whatsapp\Controller\Index;

class Display 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 parent::__construct($context);
    }

    public function execute()
    {
        return $this->_pageFactory->create();
    }
}

Mahran/Whatsapp/view/frontend/layout/whatsapp_index_display.php

<?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">
    <referenceContainer name="content">
        <block class="Mahran\Whatsapp\Block\Display" name="whatsapp_display" template="Mahran_Whatsapp::sayhello.phtml" />
    </referenceContainer>
</page>

Mahran/Whatsapp/templates/frontend/templates/sayhello.phtml

<?php

/**
 * @var \Mahran\Whatsapp\Block\Display $block
 */

echo $block->sayHello();
  • Change mahran\whatsapp to Mahran\Whatsapp – Sohel Rana Nov 24 '18 at 12:11
  • @SohelRana Sadly this did't work I have another action called Test.php that I echo "Hello World" directly inside and it's working fine. – Mostafa Mahran Nov 24 '18 at 13:09
  • @MostafaMahran does that work as per my updates made to question? – Himmat Paliwal Nov 24 '18 at 13:21
  • @HimmatPaliwal I made exactly these updates but still it's the same – Mostafa Mahran Nov 24 '18 at 13:22
  • Ok, let me check it further.. I hope you have already added the routes.xml – Himmat Paliwal Nov 24 '18 at 13:25
0

I have updated the code and added at below public repo: https://bitbucket.org/hemant2586/mahran_whatsapp/src/master/

Its working fine for me, download and check with it..

| improve this answer | |
  • It's working now ! can I understand the changes you made because I can't seem to find any difference in code that my eye could catch. – Mostafa Mahran Nov 24 '18 at 13:40
  • Not sure but it may be CamelCase issue, would suggest to check if you update the directory name accordingly and block class name in xml correctly.. <block class="Mahran\Whatsapp\Block\Display" (note the naming case) – Himmat Paliwal Nov 24 '18 at 13:42
  • How can i send my EventObserver log message by whatsapp message? @Himmat Paliwal – zus Aug 30 '19 at 7:45

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.