Pull page content using page.handle

Highlighted
New Member
2 0 3

Hey all!

Ive created individual pages for each product with an FAQ in each. These page names are identical to the product handle with the addition of -faq.

Im trying to pull in the page content on the product page but doesnt seem to work.

 

If i call it directly it works perfectly

<div>{{ pages.product-name-faq.content }}</div> 

but if i try to add a more dynamic approach like below.

{% capture FAQpage %}{{ page.handle | append: '-faq' }}{% endcapture %}

or

{% capture FAQpage %}{{ page.handle }}-faq{% endcapture %}

and then calling it via

<div>{{ pages[FAQpage].content }}</div>

i dont get any results??

 

0 Likes
Highlighted
Shopify Expert
10007 116 1816

This would be the correct code for grabbing a page with a variable for the handle.

{% assign foo = 'bar' %}
{{ pages[foo].content }}

If you are finding that it's not working I would suggest doing two things first:

  1. output the value of FAQpage so you can see what it actually is. {{ FAQpage }}
  2. make sure the page with that handle is visible, and not set to hidden within the Admin.

Post some of the live code and a link to the page if you're still stuck.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
Highlighted
New Member
2 0 3

thanks Jason,

 

UPDATE!

 

fixed it i was stupidly using page.handle rather than product.handle on a product page.

 

Working perfectly now.

 

code for anyone interested to display page content with a name matching a products handle.

 

{% capture FAQpage %}{{ product.handle }}-faq{% endcapture %}
      
      <div>{{ pages[FAQpage].content }}</div>

 

3 Likes
Highlighted
New Member
1 0 0
<!-- the content of the About Us page -->
{{ pages.about-us.content }}

answer.jpg 
0 Likes
Highlighted
Tourist
7 0 1

You can also use square brackets syntax:

{{ pages["about-us"].content }}
0 Likes