Ad

Handle Inside An Interpolation

- 1 answer

Im building a store in shopify and Im fairly new at this.

I want to interpolate a collection.handle inside an interpolation, like this:

style="color: {{ settings.tomas_{{collection.handle}} }} !important;" 

this is in order to create a dry formula to modify the css for every collection. Ive created my page colors in settings with this pattern:

tomas_example_collection: "FFF", tomas_second: "F1F1F1"

And they work if I hard code them, but I dont know how to interpolate inside an interpolation.

What would you recommend?

Thanks!!!

Ad

Answer

You can't pass liquid inside liquid.

You need to generate the target string outside before passing it.

In your case:

{%- assign target = 'tomas_' | append: collection.handle -%}

style="color: {{ settings[target] }} !important;" 

We create a variable that will hold the string and pass it using square brackets to the settings object.

Ad
source: stackoverflow.com
Ad