0

I have a controller that needs to display text, but I get a blank page. Here is what I have:

Controller/Index/Index.php

namespace Veratad\AgeVerification\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;
            parent::__construct($context);
        }

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

Block/Ageverification.php

namespace Veratad\AgeVerification\Block;

    class Ageverification extends \Magento\Framework\View\Element\Template
    {
      private $scopeConfig;
      protected $messageManager;

      public function __construct(
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Magento\Framework\Message\ManagerInterface $messageManager)
      {

        $this->scopeConfig = $scopeConfig;
        $this->messageManager = $messageManager;

      }

      public function getAgeVerificationText()
      {
        $fail = $this->scopeConfig->getValue('veratad/general/failuretext', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
        return $this->messageManager->addError( __("$fail") );
      }
    }

view/frontend/layout/ageverification_index_index.xml

    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd" layout="1column">
        <body>
            <referenceContainer name="content">
                <block class="Veratad\AgeVerification\Block\Ageverification" name="ageverification" template="ageverification.phtml" />
            </referenceContainer>
        </body>
    </page>

view/frontend/templates/ageverification.phtml

    <h3><?php echo $this->getAgeVerificationText(); ?></h3>

When i navigate to the controller I get a white page with no error messages. Can someone see where I am going wrong?

  • Try change the file view/frontend/layout/ageverification_index_index.xml to utf8 type then clear cache and check result – Vu Tran Kien Sep 6 '18 at 0:58
  • @Thomas in which mode you are using the magento ? please check using bin/magento deploy:mode:show and if it is in production mode change it to developer mode using bin/magento deploy:mode:set developer and try . – Mac Sep 11 '18 at 10:35
1

Update the __construct() function in your block file.

Block/Ageverification.php

public function __construct(
    \Magento\Framework\View\Element\Template\Context $context,
    \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
    \Magento\Framework\Message\ManagerInterface $messageManager
) {

    $this->scopeConfig = $scopeConfig;
    $this->messageManager = $messageManager;
    parent::__construct($context);
}
  • I tried this and it does not work. – Thomas C Sep 6 '18 at 13:41
  • Is there any exit; statement somewhere in your code?. Try to find out. – Dinesh Yadav Sep 7 '18 at 4:21
0

do following changes in view/frontend/layout/ageverification_index_index.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd" layout="1column">
    <body>
        <referenceContainer name="content">
            <block class="Veratad\AgeVerification\Block\Ageverification" name="ageverification" template="Veratad_AgeVerification::ageverification.phtml" />
        </referenceContainer>
    </body>
</page>

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.