0

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

1
  • Your question is unclear, you seem to ask about header, but you are also speaking about adding a class. There isn't any class for meta title in header. So you might want to say that you want to customize a template and add something like <h1> Then the xml you are looking for might be customer_acount_create.xml
    – Claims
    Commented Oct 15, 2021 at 15:55

2 Answers 2

0

A want to add that title above "Create Account". "Create Account" and "Sign in" are in header.links

enter image description here

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.