Dynamic Liquid Variable inside Liquid tag?

Highlighted
Excursionist
63 0 14

Hi there.

Not sure if this is possible, but i am looking for a way to dynamically pull in page content based on which product is being viewed.

I was hoping i'd be able to create pages with the same handles as the products and then include the page content on the product page using something like -

{{ pages.DYNAMIC-PRODUCT-HANDLE.content }}

I have tried putting the liquid tag inside like this, but this doesn't work -

{{ pages.{{product.handle}}.content }}

I have also tried to capture the product URL and then use it, but with no luck.

Does anyone know if what i am trying to do is possible, or if there is another way to do it? Could use an iFrame, but would prefer not to.

Any help or suggestions would be much appreciated!

Thanks,
Ash.

 

0 Likes
Highlighted
Excursionist
63 0 14

Ah ha i think i have answered my own question.

 

This seems to do the job -

{% capture foo %}{{ product.handle }}{% endcapture %}

{{pages.[foo].content}}
Highlighted
Shopify Expert
10006 116 1818

Or just this:

{{ pages[product.handle].content }}

My typo was picked up in the post below. It's fixed now!

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
Highlighted
Excursionist
63 0 14

Thanks Jason..

I should have realised that was the simplest way after i found out that using square brackets was the way to do it!

Just in case anyone else wants to use it.. it will need to be product.handle rather than product-handle.. like this -

{{ pages.[product.handle].content }}
0 Likes
Highlighted

Hi Jason,

Could you help me understand why it's not working in this case:

 

{{ section.blocks[0].settings.main_img[forloop.index] | img_url: '200x' }}

I have multiple ids in my schema tags, named "main_img1", "main_img2" etc.


• I checked, "forloop.index" returns "1" in the first loop (linklists loop).

• When I manually replace [forloop.index] with "1", it's working, so it's definitely an issue with the above code.

Where did I fail here?
Thank you

C'est simple comme bonjour ! Ou presque.
Need some help to customize your website? Message me anytime: 5euros.com/profil/maxdesign
0 Likes
Highlighted
New Member
1 0 0

@MaxDesign have you find a solution? Because I also have the same problem currently... 

 

Am I trying to get a dynamic image from forloop.index and it's not working ... made many test and it's doesn't see to work properly...

 

 

{% assign Myindex = forloop.index %} // just a test to see if "forloop.index" is the problem and need to be a variable but variable still isn't working ... 
{{Myindex}} // echo my current index (1...2..3) OK
{{img_blog_[Myindex]}} //echo nothing ... 
{{settings.img_blog_[Myindex]}} //echo nothing ... 
{{settings.img_blog_1}} //echo my image currently... 

 

 

Really appreciate if you found out why it wasn't working this could have me lots of time!

0 Likes
Highlighted

Unfortunately this is not possible to my knowledge. You have to do the loop manually to match your schema ID, and if it's a big loop, then you're probably not using the best method anyways and you might have to rethink your code.

C'est simple comme bonjour ! Ou presque.
Need some help to customize your website? Message me anytime: 5euros.com/profil/maxdesign
0 Likes