Skip to content
Grav 2.0 is officially stable. Read the announcement →
General

Access image meta.yaml for Alt in markdown?

Solved by pamtbaau View solution

Started by Cath 8 years ago · 10 replies · 1505 views
8 years ago

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

![????](my-images.jpg)

Thanks

7 years ago

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

bless

7 years ago

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

ex.
copyright: '©me'
software: 'Adobe'
author: 'Me'
title: 'Image title Here'
keywords:

  • '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>

7 years ago Solution

@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:

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

The docs on processing can be found here: Processing.

last edited 02/06/19 by pamtbaau
7 years ago Robert The documentation has an example. https://learn.getgrav.org/content/media#metafiles {{ pag…

thank you! This works.
Allowing twig in markdown.

And adding this to the content

{% set image1 = page.media['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.

1 reply
7 years ago

@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.

7 years ago

@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.

7 years ago

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.

Suggested topics

Topic Participants Replies Views Activity
General · by Andy Miller, 2 days ago
0 70 2 days ago
General · by Veehem, 3 days ago
0 111 3 days ago
General · by milkboy, 4 days ago
0 113 4 days ago
General · by ian russell, 2 weeks ago
2 205 1 week ago
General · by pamtbaau, 1 month ago
2 462 2 weeks ago