3

In our theme we have a static block for the links we have in our footer. We have three blocks with Account, info and social media.

At the moment everything is hard coded with relative link paths to store pages & absolute link paths to the social media pages.

I'm wondering what is the best way to link to store pages, and know you can use cms directives

For instance there are these links for customer account pages.

<a href="{{store url='customer/account'}}">My Account</a>
<a href="{{store url='customer/address'}}">My Address</a>
<a href="{{store url='wishlist'}}">My Wishlist</a>

Why would you use this method rather than a relative path? i.e.

<a href="customer/account">My Account</a>

Is there another way to link to the customer/account page? without using the customer/account keywords?

Also why would you use something like this for a CMS page?

<a href="{{store direct_url="contact"}}">Contact Us</a>

is there a better way to link to a cms page from within a static block or another cms page?

  • These seam like fine ways to do it. Simple and to the point? Can you explain what else you have in mind? – Marius Jul 31 '14 at 10:24
  • I thought there might be a way of linking to the customer/account page without using the url path so that inncase the url path was ever changed for the for the customer/account to say client/account the links would not break – Holly Jul 31 '14 at 10:35
  • 2
    If you change the customer module route from customer to client (see here how), using the {{store}} directives will automatically generate the correct url. So you are safe. It does NOT work the same for direct_url. – Marius Jul 31 '14 at 10:38
  • I see, what if you use <a href="{{store url="contact"}}">Contact Us</a> and later change the url for your contact page? Will the correct url still be generated? – Holly Jul 31 '14 at 10:46
  • Like I said in the previous comment, it only works for module routes. I assume contact is one of your custom pages (unless you are talking about the contacts module). It does not work the same for pages. Because Magento does not know you are linking to a page, nor does it keep track of the changed url keys of static pages. You can use the widgets for links but I guess this is even worse because widgets use page ids which are not protable {{widget type="cms/widget_page_link" anchor_text="some text here" title="some title here" template="cms/widget/link/link_block.phtml" page_id="52"}} – Marius Jul 31 '14 at 10:51
6

The way you are doing it is correct.
The {{store}} directive should know how to generate the correct link even if you change the customer module route name (that is currently customer). If you change it to client (see here how) <a href="{{store url='customer/account'}}">My Account</a> will still generate the correct url.
For CMS pages you should use the widget approach so it won't be important if the page changes.

{{widget type="cms/widget_page_link" anchor_text="some text here" title="some title here" template="cms/widget/link/link_block.phtml" page_id="52"}} 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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