Solved

Removal of theme snippets

ConduciveMammal
Shopify Partner
40 1 16

According to the Unite talks, when the new OSDE launches with Sections Everywhere, the new themes will no longer be able to use snippets, which I get. But my main problem is snippets hold so much more than just reusable content, I use snippets for logical code too for things like responsive images and customer tag checking.

 

Naturally, it wouldn't make any sense whatsoever to use an entire section for simply checking customer tags, so how will this be utilised? I'd really rather not have to copy/paste this code all over my themes and then somehow maintain each of them when a change is made, so in real-life scenarios, what will be the expected functionality here?

Liam Merlyn | Shopify Developer
Accepted Solution (1)

ThibautC
Shopify Staff (Retired)
10 2 18

This is an accepted solution.

Following Unite we gathered feedback and re-assessed our plans. Frame, page and content sections will be able to use snippets after all, but will do so via a new Liquid tag, different than {% include %}, which will add some constraints on how snippets are used. The constraints are intended to make our online store platform faster, more reliable, and easier to work with. The new Liquid tag will be released shortly.

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Replies 17 (17)

ThomasBorowski
Shopify Expert
803 71 239

I think they mentioned in the Q&A (https://youtu.be/HlpOGQrRBPY?t=1318) that they're looking into replacing snippets with something equivalent for the development workflow, so something that would be part of the theme build toolchain.

 

Here's the timestamp where they go into snippets specifically: https://www.youtube.com/watch?v=HlpOGQrRBPY&feature=youtu.be&t=1580

★ Smart Upgrades, Tips and Tutorials for Shopify themes: cartpunk.com
Did my solution work? Help other Community members easily find the correct solution and apply it to their own stores by marking it as the Accepted Solution and giving it a Thumbs Up
nchan0154
Tourist
3 0 3

A tool that only compiles snippets at build time is not really an acceptable solution, unfortunately. A ton of people work on customizing existing/paid themes, and theme developers almost never provide the full source.

ThibautC
Shopify Staff (Retired)
10 2 18

This is an accepted solution.

Following Unite we gathered feedback and re-assessed our plans. Frame, page and content sections will be able to use snippets after all, but will do so via a new Liquid tag, different than {% include %}, which will add some constraints on how snippets are used. The constraints are intended to make our online store platform faster, more reliable, and easier to work with. The new Liquid tag will be released shortly.

To learn more visit the Shopify Help Center or the Community Blog.

ThibautC
Shopify Staff (Retired)
10 2 18

The replacement for the {% include %} Liquid tag has been released: {% render %}.

To learn more visit the Shopify Help Center or the Community Blog.

ThomasB_
Shopify Expert
11 0 4

What if we need to calculate or evaluate multiple values as we need to use the resulting values to modify parts of our theme's liquid? How are we supposed to achieve this with render? We're doing that a lot with include right now.

ThibautC
Shopify Staff (Retired)
10 2 18

You can use the {% capture %} tag to capture the output of the {% render %} and use it in the parent template. In cases where you have multiple resulting values, we recommend either splitting your snippet into multiple snippets, or inlining the code.

 

We understand this is a compromise and that {% render %} has some limitations compared to {% include %}, but we think the benefits around performance and code simplicity are worth it.

To learn more visit the Shopify Help Center or the Community Blog.

ThomasB_
Shopify Expert
11 0 4

Thanks for the information, @ThibautC. Yes, using capture was also our initial thought, alongside that it wouldn't work for multiple variables as you mentioned.

 

Is there an internal plan or timeframe when the deprecated include will be taken out completely? Do we need to update all out customer themes at some point?

ThibautC
Shopify Staff (Retired)
10 2 18

While {% include %} is deprecated, it will not be removed from the platform, as we don't break backward compatibility in the Liquid/Theme API. However, as part of the new Online Store design experience we are introducing three new types of section files where the {% include %} tag will not be supported.

To learn more visit the Shopify Help Center or the Community Blog.

ThomasB_
Shopify Expert
11 0 4

I see, thanks for the clarification.

WillMcFarland
Shopify Partner
4 1 4

As far as I can tell from poking around, `{% include %}` is not supported within a `{% render %}`ed snippet, so if a Legacy Section Theme updates to using `{% render %}` for snippets prior to the full release of the new storefront, that will mean any apps that are relying on `{% include %}` within these snippets won't work - is that correct?

ThibautC
Shopify Staff (Retired)
10 2 18

Correct. Not ideal right now, but we think it'll be better in the long run.

To learn more visit the Shopify Help Center or the Community Blog.

JohnAtBonify
Shopify Partner
136 7 34

@ThibautCyou said...

 

While {% include %} is deprecated, it will not be removed from the platform, as we don't break backward compatibility in the Liquid/Theme API.

I came across this screenshot "in the wild" this morning. Am I misunderstanding or did this roll out as a breaking change for some stores? As an app developer with thousands of customers relying on "include", I'm extremely concerned about this. Is my concern unfounded? I don't yet have support requests about this but I don't know if I should be expecting them to start rolling in at any moment.

Screenshot 2019-11-06 13.37.55.png

ConduciveMammal
Shopify Partner
40 1 16

For this to have happened, the developer will have had to have used a {% include %} tag from within a {% render %} tag.

In terms of backwards compatibility, this shouldn't occur unless the above is done.

Liam Merlyn | Shopify Developer
ThibautC
Shopify Staff (Retired)
10 2 18

While the behavior of {% include %} remains unchanged, when a theme adopts {% render %}, it changes the behavior of snippets in a manner that can be breaking certain apps. We've communicated this in our changelog, and will hold off on using {% render %} in Debut and all theme store themes until Feb 17, 2020.

To learn more visit the Shopify Help Center or the Community Blog.

tim
Shopify Expert
3258 232 1178

You can use the {% capture %} tag to capture the output of the {% render %} and use it in the parent template. In cases where you have multiple resulting values, we recommend either splitting your snippet into multiple snippets, or inlining the code.

Would you consider adding this directly to  the  {% render %} tag as a shortcut, like:

 

{% render 'snippet' to result with value as internal_variable %}

will call snippet snippet and capture its output to the variable result?

 

I guess this could be useful  (and then supercool if snippet to output JSON and tag will parse it to make result an object :).

Because I can imagine people doing something like 

{% capture result %}
  {% render 'snippet' %}
{% end capture %}

{% assign result =  result | split: ";" %}

{% if result[0] == "something" %}
 {{ result.[1] }}
{% else %}
 {{ result.[2] }} {% endif %}

 

 

ThibautC
Shopify Staff (Retired)
10 2 18

@tim I like the to result idea. We'll consider it.

 

We considered JSON parsing but decided against it. You can read some historical context about it here.

 

Thanks for the feedback!

To learn more visit the Shopify Help Center or the Community Blog.

dungtran
Visitor
3 0 0

Thank ThibautC

i had the same problem

Tham khảo các dịch vụ sửa pin điện thoại iPhone Tại Huy Dũng
Thay pin iPhone 5s
Thay pin iPhone 7
Thay màn hình iPhone 6s