Ad

How To Link To A Custom Template In Shopify?

- 1 answer

I'm trying to add a link to a button in Shopify, but I can't get it to work. I created a new template file in Templates called "page.alternate.liquid" Then I try to link to it from header using this:

 <a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="{{ routes.page.alternate_url }}" class="header__logo-link">LINK</a>

The output doesn't add any link at all, just a regular text.

Ad

Answer

To view an alternate template, you have two options:

1) On the resource in question, choose the template that the resource should default to using the selector on the right-hand side.

(Note: this only shows if you have at least 1 appropriate alternate theme in the live theme, and will only list the alternate templates in the currently-live theme)

2) When linking to the resource, add view=<template-suffix> to the querystring of the link.

Example: To link to an alternate page template templates/page.inverted_colours.liquid, your link URL would be /pages/about-us?view=inverted_colours

In your case in the question, that would look something like <a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href=" {{ page.url }}?view=alternate_url" class="header__logo-link">LINK</a>

This article on Shopify partners blog might help as well: https://www.shopify.ca/partners/blog/shopify-alternate-templates

Hope this helps!

Ad
source: stackoverflow.com
Ad