Shopify – Get a Page’s Title, Content and More With The Handle

March 4th, 2014 - Posted by Steve Marks to Software, Web Development.

Following on from a recent e-commerce project in Shopify, I came across a scenario whereby I needed to get details about a particular page from somewhere on the site.

For examples sake, let’s imagine that I needed to get the content of an ‘About Us‘ page and display it on the homepage. There is no link between the two pages, so I needed a way to get one page’s details from another.

I was surprised to discover very little written about this subject, even within the Shopify documentation, so wanted to write about how I achieved this to help others that are looking to do exactly this.

The Solution

It turns out that there is a global ‘pages‘ variable that is available throughout the site. Using the example above, let’s imagine that we have a page called ‘About Us’ that has a handle of ‘about-us‘.

On the homepage we could do the following the get the title, content and more:

{{ pages['about-us'].title }}
{{ pages['about-us'].content }}

Easy enough right? And what about if the handle is in a liquid variable? Well, then we can do something like so:

{% assign my_var = "about-us" %}

{{ pages[my_var].title }}
{{ pages[my_var].content }} 

Using the above method, you could get anything about a particular page, not just the title and content. You could, for example, get the author, URL, date added etc. basically anything that is available from within Shopify’s single page variable.

This entry was posted on Tuesday, March 4th, 2014 at 7:00 pm by +Steve Marks and is filed under Software, Web Development. You can follow any responses to this entry through the RSS 2.0 feed.

Fear not, we won't publish this

Comments (2)
  1. Alekka says:

    Thanks for providing that. Strange that Shopify dont have this even in their documentation.

  2. Juni says:

    Woa! this actually helped me. Thanks a lot!