Print twig inside .html() action

Hey there!
I have the following snippet:

{{ image.html('My title', 'alt', 'myclass') }}

Can I print twig inside this .html() action? For example to output a special alt-tag defined in the page header of the corresponding markdown file?

I tried the following, but this doesn’t work.

{{ image.html('My title', '{{ page.header.imagemeta }} ', 'myclass') }}

Is it possible to get this to work somehow?

it’s even easier:

{{ image.html('My title', page.header.imagemeta, 'myclass') }}

omg, I love you guys and Grav so much <3
I tried this, but inside quotes and it didn’t work. Your solution works like a charm.
Thank you! It seems like everything I can imagine is somehow possible with Grav. This is soo cool!

heh no problem. BTW, for your better understanding, the quotes are a string literal, as the encompassing display backets: {{ }} already are indicating you are writing Twig, you can use variables directly, and that one, evaluates to a string, so you don’t need the quotes. Hope that makes sense.

BTW, if you love Grav all we ask is you spread the word :slight_smile: The more people that use and contribute to Grav, the better it becomes for everyone!

Hah! Seems like a typical beginners mistake. I should have known better.
Anyways… thanks again and I’ll do my best to tell everyone about Grav.
Have a great day!

You need to filter the variable page.header.imagemeta:

{{ image.html('My title', page.header.imagemeta | e('html_attr'), 'myclass') }}

Here the reference:

Oh alright! Thanks for your additional information. Didn’t know that…

You can use every filters/functions from Twig (this library used for parse the templates). You are welcome! :slight_smile: