Forum Discussion
Using Liquid for image URL
Hi David_M
How about using a Catalog as a controller with the below structure? It's much cleaner and your HTML template never needs to be touched again. All image updates are managed straight from the catalog table.
| id | hero_img_url | footer_img_url |
|-----|-------------|----------------|
| en | https://... | https://... |
| fr | https://... | https://... |
| de | https://... | https://... |
The id maps directly to the language attribute on the user profile. Then in your template, just add this Liquid once at the top (or store it in a content block and call the contentblock) :
{% assign lang = {{${language}}} | default: 'en' | downcase %}
{% catalog_items daily_images {{lang}} %}
{% if items[0] == blank %}
{% catalog_items daily_images en %}
{% endif %}And reference the images in your HTML like this:
- <img src="{{ items[0].hero_img_url }}" width="600">
- <img src="{{ items[0].footer_img_url }}" width="600">
No if/else statements for each language. No HTML edits. The catalog lookup handles all 13 languages dynamically in one go.
Each day, the only job is to update the URLs in the catalog table or you can import a csv to a catalog.
And tomorrow if you want to automate this process, you can use the Catalog API to update the relevant language image URLs in one single PATCH call. Pipe it straight from your CMS or DAM and it's fully hands-off.
Hope this helps!