Reputation: 1
I am following the lektor guide to set up a portfolio site. My goal is to include a caption below each image displayed using the projects.html
and project.html
templates.
My first thought was to use attachment metadata, as that would make it simple to customize the caption content for each image attachment. However, I was unable to find any documentation or examples on how to achieve the desired result.
As an example, assume I have created a project page first-project
and added an attachment image001.jpg
to the project. The metadata file path for this attachment is /content/projects/first-project/image001.jpg.lr
and here are its contents:
_model: image
---
description: An example caption for image001.jpg
---
photographer: Photographer
---
copyright: 2023 by Photographer
How can I access these metadata fields from within the projects.html
and project.html
templates?
I have tried accessing them from the image object created within the template (e.g. {{ image.description }}
, {{ image.photographer }}
, etc.) but nothing is returned.
I am also aware that other image data can be accessed via templates such as image.width
, image.height
, image.exif.description
. Although I could use something like the EXIF description it would be preferable to avoid including the caption text within the image EXIF data if possible.
Is using attachment metadata a reasonable method for achieving my goal? Would it be simpler to just use the description field in the image EXIF data? Or instead should I be using a different approach as this is not the intended purpose of attachment metadata? (e.g. something like content flow).
Any feedback or suggestions are appreciated!
Upvotes: 0
Views: 99
Reputation: 1
This is possible using attachment metadata. The additional requirement is to create a a model /models/image.ini
with the desired fields:
[model]
name = Image
label = {{ this.title }}
[fields.description]
label = Description
type = string
[fields.photographer]
label = Description
type = string
[fields.copyright]
label = Copyright
type = string
The fields can then be referenced within the template (e.g. {{ image.description }}
). If the model has a different name such as img.ini
then this should be included in the metadata file image001.jpg.lr
:
_model: img
---
description: An example caption for image001.jpg
Upvotes: 0