php Magento 2.2将搜索移动到导航-带代码

amrnrhlw  于 2023-03-28  发布在  PHP
关注(0)|答案(1)|浏览(138)

我正试图移动到Magento 2.2上的导航搜索栏使用一个儿童主题。
目前,我的magento_demo\app\design\frontend\Magento\themename\Magento_Theme\layout\default.xml文件包含

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>

    <referenceBlock name="wish-list-link" remove="true" />          <!--for WishList Link-->
    <referenceBlock name="my-account-link" remove="true" />         <!--for My Account Link-->

    <referenceBlock name="logo">
        <arguments>
            <argument name="logo_file" xsi:type="string">images/mytheme-logo.png</argument>
            <argument name="logo_img_width" xsi:type="number">200</argument>
            <argument name="logo_img_height" xsi:type="number">200</argument>
        </arguments>
    </referenceBlock>
</body>

我做了些调查发现

<move element="top.search" destination="page.top" after="catalog.topnav" />

不幸的是,我没有运气。如果有人能很好地解释这是如何工作的,那就太好了,因为我需要移动很多元素!
希望有人能理解这一点,因为我已经用完了尝试的选项!

5jdjgkvh

5jdjgkvh1#

要将搜索栏从标题移动到彩色导航菜单(带有类别链接),您只需:
1.创建一个文件:src/app/design/frontend/[Vendor_Name]/[Theme_Name]/Magento_Theme/layout/default.xml
1.这样写:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <!-- Move top.search in navigation menu -->
        <referenceBlock name="catalog.topnav">
            <block class="Magento\Framework\View\Element\Template" name="top.search" as="topSearch" template="Magento_Search::form.mini.phtml">
                <arguments>
                    <argument name="configProvider" xsi:type="object">Magento\Search\ViewModel\ConfigProvider</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>

1.然后复制:/src/vendor/magento/module-theme/view/frontend/templates/html/topmenu.phtml到你的主题src/app/design/frontend/[Vendor_Name]/[Theme_Name]/Magento_Theme/templates/html/topmenu.phtml
1.在topmenu.phtml中替换

<ul data-mage-init='{"menu":{"responsive":true, "expanded":true, "position":{"my":"left top","at":"left bottom"}}}'>
        <?= /* @noEscape */ $_menuHtml?>
        <?= $block->getChildHtml() ?>
    </ul>

<ul data-mage-init='{"menu":{"responsive":true, "expanded":true, "position":{"my":"left top","at":"left bottom"}}}'>
        <?= /* @noEscape */ $_menuHtml?>
    </ul>
    <?= $block->getBlockHtml('top.search') ?>

1.重新生成静态文件

相关问题