I've searched all over google and I found a few tutorials that seems straight forward but I can't get it to work in my default.xml
.
Majority of the tutorials uses local.xml but I'm not sure where to find that.
Basically, I removed all the top links and added my own. Here is what I have below. This works BUT I need to be able to add a css class and a target of blank.
Any help would be appreciated:
<referenceBlock name="top.links">
<!-- add ahern access link -->
<block class="Magento\Framework\View\Element\Html\Link\Current" name="ahern-access-link" htmlClass="ahern-access">
<arguments>
<argument name="label" xsi:type="string">Ahern Access</argument>
<argument name="path" xsi:type="string">http://ahernaccess.com</argument>
<argument name="title" xsi:type="string">Log In to Ahern Access</argument>
<argument name="class" xsi:type="string">ahern-access</argument>
</arguments>
</block>
<!-- remove existing blocks -->
<referenceBlock name="header" remove="true" />
<referenceBlock name="register-link" remove="true" />
<referenceBlock name="authorization-link" remove="true" />
<referenceBlock name="wish-list-link" remove="true" />
<referenceBlock name="my-account-link" remove="true" />
</referenceBlock>
Or if there is a way to reference a CMS block in default.xml
?
Best Answer
Try something like this:
I'm doing some digging in as i have yet to see the target argument used in the wild. If you look at this file /vendor/magento/framework/View/Element/Html/Link/Current.php you will see the list of possible arguments you can make in the comments at the top
Which target is not in. But looking at a few other
default.xml
files, i see things like this in /vendor/magento/module-theme/view/frontend/layout/default.xml:Which relate back to the Template class. So the concept is there, but i'm not 100% on how M2 is implementing that.
For me I have to play around with XML for a while before i land on the exact solution that i need. So i hope this helps.
Another idea would be to add the link directly to the template file (i think you are needing /vendor/magento/module-theme/view/frontend/templates/html/header.phtml in this case). It's not an elegent solution, but given that the target="_blank" is not a part of the class, you would have to create a class override to get this functionality in the XML's.