d
Topic
Posts:
10
July 16, 2006

Liquid includes / partials This post is outdated

Suppose I want the same bit of content on different pages, or in different positions on the same page. For example, in my partner's shop we were looking at some content related to products of a certain type, and we were thinking about that content appearing on all products of that type, and also on the collection page for products of that type. The conditional logic is easy enough - but I wanted to avoid cut-and-paste of the shared content. To share simple content that doesn't use anything more complicated than textile, then I can create some page entitled 'The shared stuff' and then use > @{% pages.the-shared-stuff.content %}@ in the relevant templates. This template/page separation is also useful to allow my parner to be able to edit separate bits of text content without her having to touch mark-up and liquid templates. However, I ran into a case where the content we wanted to share was best generated from a liquid template. In this particular case it was just because I wanted to be able to use @asset_url@ for an image rather hardcoding the resulting long (presumed volatile) URL. But of course there are many cases that would absolutely require using liquid. Having done some digging around in the liquid docs and then the code I found the @include@ tag. I downloaded my site theme, added a @_the_shared_stuff.liquid@ template and reuploaded. (This is a slightly awkward workflow, from which I take the hint that I may be stretching intended use a bit here.) But my templates that feature > @{% include 'the_shared_stuff' %}@ still fail to compile. (An example error was 7310-88-24-63-998e18, and the real world template name is @pouch_explanation@. By the way, I found it hard to read the reports of these failures without switching off stylesheets.) I don't care much about getting this to work - our store is simple and doesn't really need these finesses, I'm just playing - but thought I should report / query the issue. --Anthony.
i
Replies
Posts:
734
July 22, 2006

For placing a description specific to each collection, follow the steps I posted in a reply to this comment: http://forums.shopify.com/community/design/post/1720.

Then, if you also want to have the same text appear on each product belonging to that collection, paste the following into your product.liquid (with the percentage signs in the right places):

{ for article in blogs.collectiontexts.articles }

{ if article.title == product.type }

{{ article.content}}

{ endif }

{ endfor }

operation absurdist feature requests: terminated (http://en.wikipedia.org/wiki/Absurdism)
Posts:
2056
July 29, 2006

Include is still disabled in shopify’s liquid code so thats why you see the poof message.

What you basically want is to use liquid in the content which is rendered. This is an interesting idea and i can definitely see use cases for it like the asset_url you mentioned or even using pages as sort of common content partials in many different products.

The issue with this is a unpopular one. Speed. If we were to enable this we would have to re-parse, compile and interprete all code which comes from {{ }} content tags. This would increase the CPU requirements of rendering a template dramatically.

I’ll toy with the idea when i start work on the next interation of shopify’s liquid support ( code name: total freedom ) but can’t make any promises at this point.

Tobias Lütke - Shopify CEO // http://twitter.com/tobi
Posts:
10
July 30, 2006

Christina, thanks for the neat idea of using a blog as a general holder for an iterable collection of texts.

Tobi, understood with respect to partials and speed, and as stated, definitely not an issue for our tiny shop. I’m just playing.

I would guess that some alternative to hard-coding into page content URLs that are coupled to the current implementation might be handy. It is in particular very tempting to use assets hosted on Shopify for images within pages, and presumably such pages will be a bit fragile. Perhaps you could translate a less concrete asset reference at the same time as the textify translations are done. But this is just an idle idea from a distance.

Log in or sign up for an account to reply.

This thread has been closed! You will not be able to reply.