Contao: TwigExtension for outputting image (templates)

Created on 9 Mar 2020  路  3Comments  路  Source: contao/contao

I'm using twig quite heavily in my own projects. One thing that's always a bit cumbersome by default though is working with images.

So lately I've been adding a PictureExtension that can output a rendered image template like so:

{{ picture(uuid, 'my_picture_size')|raw }}

(...or output the individual data values and recreate the template in a macro)

Wdyt about shipping something like this (or better) by default?
For me this sped up development quite a bit. :smile:

feature

Most helpful comment

sounds legit to me. Maybe a feature for 4.10? I don't like the |raw though, I think an extension can tell whether it will "ship" safe HTML?

All 3 comments

sounds legit to me. Maybe a feature for 4.10? I don't like the |raw though, I think an extension can tell whether it will "ship" safe HTML?

I think an extension can tell whether it will "ship" safe HTML?

Ah sure yes :smile: , I'm actually using this and forget about it. You can pass an option ['is_safe' => ['html']] to a function/filter, so that the call can become this:

{{ picture(uuid, 'my_picture_size') }}

See #1528

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mathContao picture mathContao  路  3Comments

leofeyer picture leofeyer  路  3Comments

kikmedia picture kikmedia  路  4Comments

xchs picture xchs  路  3Comments

Alibi-Contao picture Alibi-Contao  路  3Comments