Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Give Liquid-templated <img> a class in Locomotive

I have the following liquid markup:

{{ 'image.jpg' | theme_image_tag }}

and it renders like,

<img src="/site.com/site/3424242/image.jpg" />

How to add a class or whatever option to it? I want it to render like:

<img src="/site.com/site/3424242/image.jpg" class="thumbnail" />

I use the Locomotive CMS and the liquid that comes with it.

like image 801
aouaou Avatar asked Jul 16 '11 14:07

aouaou


2 Answers

For the most control, consider using theme_image_url instead of theme_image_tag. Here's a more detailed example that should get you want you want.

<img src="{{ 'image.jpg' | theme_image_url }}" class="thumbnail" />

like image 97
M. Scott Ford Avatar answered Sep 23 '22 15:09

M. Scott Ford


Although the docs don't make this clear, you can add classes to the image_tag or theme_image_tag filters like this:

{{ "image.png" | image_tag: "class:image" }}

More generally, you can add arbitrary HTML attributes. Liquid code like this...

{{ "image.png" | image_tag: "id:foo", "some_custom_attr:bar" }}

will produce HTML like this:

<img src="image.png" id="foo" some_custom_attr="bar">
like image 36
Didde Avatar answered Sep 23 '22 15:09

Didde