【问题标题】:Magento 2.4 page broken layoutMagento 2.4 页面损坏的布局
【发布时间】:2021-12-30 15:31:42
【问题描述】:

我在 Magento 2.4.x 中遇到页面布局问题

现在我已经在一个测试模块中创建了一个测试页面。

按照所有必要的步骤在页面上使用默认主题显示一些文本。我看到了输出,但页面布局损坏。

我想知道我在这个过程中做错了什么。

请指教。

模块文件如下

路线:Tadawi\Helloworld5\etc\frontend\routes.xml

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route id="helloworldroute" frontName="helloworld">
            <module name="Tadawi_Helloworld5"/>
        </route>
    </router>
</config>

控制器:Tadawi\Helloworld5\Controller\Index\Index.php

<?php
namespace Tadawi\Helloworld5\Controller\Index;

use Magento\Framework\Controller\ResultFactory;

class Index extends \Magento\Framework\App\Action\Action
{

    /** @var \Magento\Framework\View\Result\PageFactory  */
    protected $resultPageFactory;

    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $resultPageFactory
    ) {
        $this->resultPageFactory = $resultPageFactory;
        parent::__construct($context);
    }
    
    public function execute()
    {
        $resultPage =$this->resultPageFactory->create();              
        return $resultPage;
    }
}

布局文件:Tadawi\Helloworld5\view\frontend\layout\helloworldroute_index_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <referenceContainer name="content">
        <block class="Tadawi\Helloworld5\Block\Index" name="helloworld.index" template="Tadawi_Helloworld5::index.phtml" />
    </referenceContainer>
</page>

模板文件:Tadawi\Helloworld5\view\frontend\templates\index.phtml

<h2>Hello World</h2>

<p>Hello and welcome!</p>

这是我调用路由时得到的输出

【问题讨论】:

    标签: layout magento2.4


    【解决方案1】:

    您还需要添加您在此提到的此文件块文件。

    或者您可以简单地添加 '\Magento\Framework\View\Element\Template' 而不是类

    也尝试运行下面的命令,然后检查

    php bin/magento se:up php bin/magento s:d:c php bin/magento s:s:d -f php bin/magento c:f

    这可能会帮助您解决问题。

    【讨论】:

      猜你喜欢
      • 2015-11-23
      • 2021-12-27
      • 2014-06-17
      • 2015-10-16
      • 2012-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多