Give Liquid-templated <img> class in Locomotive
I have the following liquid markup:
{{ 'image.jpg' | theme_image_tag }} and it displays how
<img src="/site.com/site/3424242/image.jpg" /> How to add a class or any other option? I want it to look like this:
<img src="/site.com/site/3424242/image.jpg" class="thumbnail" /> I use Locomotive CMS and the fluid that comes with it.
Although the documents do not make this clear, you can add classes to the image_tag or theme_image_tag as follows:
{{ "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 create HTML as follows:
<img src="image.png" id="foo" some_custom_attr="bar"> If you want to customize your fluid, you can consider editing the html.rb file located in lib / locomotive / liquid / filters / html.rb.
def my_custom_tag (input,*args) "<img src=\"#{theme_image_url(input)}\" class=\"#{args.first}\" />" end Or you can even edit the current theme_image_tag filter.
the difference between image_tag and theme_image_tag is taht image_tag will give you the url from the data you uploaded to your server, and theme_image_tag will give you the one you get from your theme.
both take parameters.
{{ '/public/images/exemple.jpg' | theme_image_tag:'class: c1,c2'}} {% for blog_post in contents.blog_posts%} {{ blog_post.image.url | image_tag, 'alt:my beautyfull image', 'id:exemple'}} {% endfor %} amuses Horion grรฉgory