Answers:
通过创建新模块来添加新块。例如 :
在中建立新目录 app/code/
在此创建另一个文件夹 Foo/Bar
要创建模块,请在中创建module.xml Foo/Bar/etc/module.xml。
并粘贴此代码
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Foo_Bar" setup_version="2.0.1"/>
</config>
php bin/magento setup:upgrade在用于创建模块的CLI中运行此命令。
创建 Foo/Bar/Block/Baz.php
并粘贴此代码
<?php
namespace Foo\Bar\Block;
class Baz
extends \Magento\Framework\View\Element\Template
{
public function getTitle()
{
return "New Block";
}
}
创建 Foo/Bar/view/frontend/layout/customer_account_login.xml
并粘贴此代码
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Foo\Bar\Block\Baz" template="Foo_Bar::default/baz.phtml"/>
</referenceContainer>
</body>
</page>
创建 Foo/Bar/view/frontend/templates/default/baz.phtml
并粘贴此代码
<?php
?>
<h1tag><?php echo $block->getTitle(); ?></h1tag>
删除缓存并通过重新加载登录页面检查您的块。
通过小部件添加,添加CMS静态块类型的新小部件,然后在小部件选项中选择您的特定页面。