In my header links, right now I have "Create account" and "Sign in" and before those I want to add a title "My account" with a certain class, but I don't know how I can do this. I know I have to modify default.xml from Magento Theme. I passed arguments from different methods from internet but nothing change. Can you help me with this? I work with Magento 2.4
2 Answers
Take a look at the places where Magento does this already. If you take a look at the customer modules default.xml:
vendor/magento/module-customer/view/frontend/layout/default.xml
You will see a call to the code that creates the sign in link:
<referenceBlock name="top.links">
<block class="Magento\Customer\Block\Account\Link" name="my-account-link">
<arguments>
<argument name="label" xsi:type="string" translate="true">My Account</argument>
</arguments>
</block>
<block class="Magento\Customer\Block\Account\RegisterLink" name="register-link">
<arguments>
<argument name="label" xsi:type="string" translate="true">Create an Account</argument>
</arguments>
</block>
<block class="Magento\Customer\Block\Account\AuthorizationLink" name="authorization-link"
template="account/link/authorization.phtml"/>
</referenceBlock>
I'm pointing out the AuthorizationLink
class in this code. This makes a call to a template file that has the logic that fills in the conditions for having a link that changes based on if the user is logged in or not.
/** @var $block \Magento\Customer\Block\Account\AuthorizationLink */
$dataPostParam = '';
if ($block->isLoggedIn()) {
$dataPostParam = sprintf(" data-post='%s'", $block->getPostParams());
}
?>
<li class="authorization-link" data-label="<?php echo $block->escapeHtml(__('or')); ?>">
<a <?php /* @escapeNotVerified */ echo $block->getLinkAttributes(); ?><?php /* @escapeNotVerified */ echo $dataPostParam; ?>>
<?php echo $block->escapeHtml($block->getLabel()); ?>
</a>
</li>
While is isn't exactly what you are looking to do (magento always does it's work in the most convoluted way possible), it's a way in the theme to add in blocks that call in templates that will do the kind of work you are looking for.
<h1>
Then the xml you are looking for might becustomer_acount_create.xml