Happening now | Office Hours: Customizing Your Theme With Moeed | Ask your questions now!

How to create reusable content in Shopify 2.0 editor?

How to create reusable content in Shopify 2.0 editor?

Ben31
Trailblazer
221 8 160

Hi There, sorry if this is easy but how do you create reusable content for use in the 2.0 editor?

 

Everyone suggests Metafields but they can't have defaults as far as I can tell - is that correct? And because reusable content blocks often need to fit within editor blocks (and in different places product depending), hard-coding them can be painful. And if they are hard-coded, editors no longer have easy access and hard-coded content tends to make theme updates more painful.

 

e.g. Say you have product-based content that applies to many but not all your products. It seems you have to create a product Metafield, manually add identical content to each product, and if that content needs to appear on different page-types (pages, blogs etc) you have to duplicate the Metafields all over again.

 

Then when content needs updating (as it always does!) you have to manually update the Metafields one at a time, is that correct? If so, Metafields seem great for small snippets of unique data but impractical for reusable content.

 

Or are we missing something basic? Any help very much appreciated! Cheers, Ben

Replies 3 (3)

biznazz101
Shopify Partner
494 50 103

It will depend on the content to determine the best method, but it sounds like you should use page, product, blog templates etc.

You can create a unique template which contains the info that needs to be shown for multiple pages. Then assign it to your products, or pages as needed. That way you don't need to fill out the info for every page/product but just do it once for the template instead.

More Info: https://help.shopify.com/en/manual/online-store/themes/theme-structure/templates

I hope that is helpful!
@biznazz101 

Don't hesitate to reach out for more help with your store.
SEE OUR TASK STORE or check us out via our profile! FREE STORE AUDIT
Ben31
Trailblazer
221 8 160

@biznazz101 Thanks for the reply but unless I'm misunderstanding, that kind of template hard-coding is exactly what we're trying to avoid sorry.

 

One workaround I've just tested is to create a snippet in the theme, then use custom liquid to pull and render the snippet like this... 

 

{% render 'snippet-name' %}

 

Now the snippet can be placed and re-ordered using the editor wherever Custom Liquid can appear, even within other sections like the product section...

 

custom-liquid-block.jpg

 

But obviously this requires people comfortable with coding to setup and maintain.

 

Also, this method intermingles content with theme code which we're finding increasingly painful with the way themes are updated on Shopify because there doesn't seem to be an obvious/easy way of separating customisations from the core theme (that we can find).

 

Does anyone have a better solution?

 

Cheers, Ben

biznazz101
Shopify Partner
494 50 103

Hi Ben,
What you describe above (rendering a snippet based on specific conditions) is another effective way to customize products or other pages in your store. The issue for most with this method is that you need to understand where to place the code and how to write it. For example:

 

 

 {% if product.handle contains 'monthly'%}
{% render 'monthly-snippet' %}
{% endif %}

 

 


If your goal is to avoid having to use the "Edit Code" function or adding to/editing your theme files, I would recommend using the Theme Editor as I mentioned in my original reply. You are correct, this method will also create new code files in your theme, but you will not need to write or edit any of this code it will be generated automatically. All changes to the Templates would be mad in the built-in Theme Editor, then you simply assign them to your products or pages.

As far as I know these are really the two options for changing or adding unique content:
Edit The Code Yourself OR Use Shopify's Built In Options (Theme Editor)

Here is a good overview of the method I am referring to:
https://youtu.be/rppKgzoAkQc?si=6y45fr18Dxl2ylFX&t=282

It will really depend on how many content sections you need, if it is going to be more than what is possible using the theme editor (25 sections per template, which is a lot most pages will only need 3-8) then I would start using snippets to render the content. Otherwise I'd recommend doing what you can with the Theme Editor, it will be much simpler overall since you won't have to mess around with code.

Hope that is helpful!
@biznazz101

Don't hesitate to reach out for more help with your store.
SEE OUR TASK STORE or check us out via our profile! FREE STORE AUDIT