Image metadata file

Looking to provide a caption for image files in a post, I tried using the documented an_image.jpg.meta.yaml. But having trouble accessing a field in the header or determining the exact structure of that met file. Docs are weak in this area so any direction welcome.

I admit they are a weak with that because the .yaml is not fully fleshed out and supported yet. However, there is an easier solution. Simply use the Markdown image format to provide the Alt text:

![Alt text]( "Image Title")

Thanks but need to do this in a template with Twig. Guess I could name the file with the caption I want - is there a function that returns just the name of the media item or I guess I could just use php/twig.

Let me test something…

Ok, just ran a quick test.

First I have a file called sample-image.jpg, so I created a file called sample-image.jpg.meta.yaml and in that file I put:

alt_text: My Alt Text
width: 900px
description: A sample description here.

Then i dumped out the object in my Twig with:

{{ dump(['sample-image.jpg']) }}

Then in my browser (with debugger enabled of course), I can see the object in the Messages panel:

Media | Demo2 2014-12-29 11-54-52

Scrolling down to the bottom I can see:

#items: array:15 [
    "type" => "image"
    "thumb" => "/Users/rhuk/workspace/grav-demo-sampler/user/pages/ age.jpg"
    "mime" => "image/jpeg"
    "image" => array:1 [
      "filters" => array:1 [
        "default" => array:1 [
          0 => "enableProgressive"
    "name" => "sample-image.jpg"
    "filename" => "sample-image.jpg"
    "basename" => "sample-image"
    "extension" => "jpg"
    "path" => "/Users/rhuk/workspace/grav-demo-sampler/user/pages/"
    "modified" => 1414346083
    "width" => "900px"
    "height" => 768
    "size" => 74
    "alt_text" => "My Alt Text"
    "description" => "A sample description here."

So then I can see the values are showing up in the object as expected and I can access them directly such as:

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

and it simply displays:

My Alt Text

Works fine! I love it when a plan comes together!

Perfect, Andy, works a treat – playing about with the blog skeleton for my eldest’s site and nearly done. The skeleton makes life very easy and helps to familiarise with Grav for a bigger project. Will send you a link when my hosting updates me to PHP 5.5 (still rockin’ 5.3!)