Access image meta.yaml for Alt in markdown?

image.meta.caption works in the twig files…
but how do I access the meta in markdown?



welcome @Ckka,
please explain well what are you going to do


Using Quark template
I’m uploading images that are automatically generating a meta.yaml

copyright: ‘©me’
software: ‘Adobe’
author: ‘Me’
title: ‘Image title Here’

  • ‘keyone’
  • ‘keyone’
    caption: ‘caption here’
    headline: ‘headline here’

In the admin > content with the markdown editor I’m adding images from the Page Media.

The image displays on the front-end with the alt=’ is blank

I would like to use the caption in the meta.yaml to auto populate the alt=’ but I cannot seem to figure out how the image (inside of the the content box) is created.

<figure role='group'><img src="http://klkls" alt></figure>

Are you using a specific plugin?

The documentation has an example.

{{['sample-image.jpg'].meta.alt_text }}

@Ckka I am afraid the above mentioned example from the docs will not work by its own. For performance reasons, by default, Grav does not process Twig inside Markdown.

By default Grav will process markdown but will not process twig in a page.

To allow Twig being processed inside Markdown, the ‘process’ setting is required in the header of the page:

title: My title
    twig: true   <-- this will tell Grav to process Twig in Markdown
{{['sample-image.jpg'].meta.alt_text }}

The docs on processing can be found here: Processing.

thank you! This works.
Allowing twig in markdown.

And adding this to the content

{% set image1 =[‘image1.jpg’] %}
{{ image1.meta.caption }}

I’m not sure this is the most efficient way to do this.
All single pages will have to process images in this manner.
But I am still wrapping my head around twig, markdown, and grav…

Thanks for your help! Much appreciated.

@Ckka If I understand Grav’s caching correctly…

The processing of Twig in Markdown only happens when the cache needs to be (re)build (e.g. page change, system.yaml change, …). Once cached, the page will not be processed again for following requests.

Instead of adding the twig to every page and enable twig in the frontmatter, you could also consider adding processing the images inside your page template. More or less like is done with the hero image in Quark.

@metbril, I’m not sure how that will fly with images embedded in the content of pages…

At the very top or bottom of the page, OK, but anywhere else would be inefficient (e.g. regex) in Twig templates.

The OP has not explained how he is using the images and if they need to be in the generated page or in a specific place inside the (markdown) content. If the former, than adding it to the template is a viable alternative.