Ad

How Do I Allow Users To Use Liquid In Shopify Theme Settings?

- 1 answer

I am modifying a theme for the designers at work, and I was wanting to allow theme to insert bits of liquid code so they can place variables wherever they want, such as some number variables inside of text. How would I do this? If not liquid, is there a simple way of allowing them to use variables in text?

Ad

Answer

You can add placeholder text to your theme settings that you can then replace with liquid filters ( https://help.shopify.com/themes/liquid/filters/string-filters#replace )

For example in your theme settings you'd have something like this: --somevariable--

Then in your theme liquid code you can find the text placeholder and replace it with the variable: {{ settings.123 | replace: '--somevariable--', product.title }}

Ad
source: stackoverflow.com
Ad