Magento2在帐户仪表板中管理导航链接
简短指南将帮助您了解如何在Magento 2的前端客户帐户仪表板中管理导航链接。
在下面的示例中,您将学习如何
- 添加新的自定义链接
- 删除现有链接
- 重新排列链接
- 更改链接标签
在客户的帐户信息中心中。
首先,在您的主题中创建一个名为customer_account.xml的新XML文件,例如下面的文件路径,
示例文件路径:app/design/frontend/SunTheme/Yang/Magento_Customer/layout/customer_account.xml
添加新的自定义链接
这是您需要按如下方式添加到布局XML文件(customer_account.xml)中的示例代码,这有助于在Magento 2前端的客户帐户仪表板中添加新的自定义链接。
<?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>
<referenceBlock name="customer_account_navigation">
<block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-custom-link" after="-" >
<arguments>
<argument name="label" xsi:type="string" translate="true">Custom Link Label</argument>
<argument name="path" xsi:type="string">custom-link-path</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
在上面的代码中,将提及custom-link-path及其路径,即模块/控制器/动作。
删除现有链接
这是您需要按如下方式添加到布局XML文件(customer_account.xml)中的示例代码,这有助于从Magento 2前端中的客户帐户仪表板中删除导航链接。
<?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>
<!-- To Remove Remove Account Dashboard-->
<referenceBlock name="customer-account-navigation-account-link" remove="true"/>
<!-- To Remove Account Information-->
<referenceBlock name="customer-account-navigation-account-edit-link" remove="true"/>
<!-- To Remove Address Book-->
<referenceBlock name="customer-account-navigation-address-link" remove="true"/>
<!-- To Remove My Orders-->
<referenceBlock name="customer-account-navigation-orders-link" remove="true"/>
<!-- To Remove My Downloadable Products-->
<referenceBlock name="customer-account-navigation-downloadable-products-link" remove="true"/>
<!-- To Remove Newsletter Subscriptions-->
<referenceBlock name="customer-account-navigation-newsletter-subscriptions-link" remove="true"/>
<!-- To Remove My Credit Cards-->
<referenceBlock name="customer-account-navigation-my-credit-cards-link" remove="true"/>
<!-- To Remove Billing Agreements-->
<referenceBlock name="customer-account-navigation-billing-agreements-link" remove="true"/>
<!-- To Remove My Product Reviews-->
<referenceBlock name="customer-account-navigation-product-reviews-link" remove="true"/>
<!-- To Remove My Wish List-->
<referenceBlock name="customer-account-navigation-wish-list-link" remove="true"/>
<!-- For Enterprise -->
<!-- To Remove Gift card link -->
<referenceBlock name="customer-account-navigation-gift-card-link" remove="true"/>
<!-- To Remove Order by SKU -->
<referenceBlock name="customer-account-navigation-checkout-sku-link" remove="true"/>
<!-- To Remove Gift registry -->
<referenceBlock name="customer-account-navigation-giftregistry-link" remove="true"/>
<!-- To Remove Reward points -->
<referenceBlock name="customer-account-navigation-reward-link" remove="true"/>
<!-- To Remove My Invitations -->
<referenceBlock name="customer-account-navigation-magento-invitation-link-container" remove="true"/>
<!-- To Remove Stored Payment Methods -->
<referenceBlock name="customer-account-navigation-my-credit-cards-link" remove="true"></referenceBlock>
<!-- To Remove My Returns -->
<referenceBlock name="customer-account-navigation-return-history-link" remove="true"></referenceBlock>
<!-- To Remove Store Credit -->
<referenceBlock name="customer-account-navigation-customer-balance-link" remove="true"></referenceBlock>
</body>
</page>