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

Image Assets in .md header

Started by Muut Archive 11 years ago · 2 replies · 255 views
11 years ago

I'd like to have a custom page header containing an image asset. Something like:
---
title: Page Title
banner: image.jpg
---

Adding {{ header.banner }} to the template outputs the image filename, but the path is incorrect so the image doesn't work.

How can I link to an image asset using a variable from the header?

11 years ago

I guess the ultimate question is where is the image stored? that directly effects the URL. if it's simply in the same folder as the page, You can do something like:

TWIG
{{ page.media[header.banner].url() }}
11 years ago

Apologies, I forgot to mention that critical piece of info. The image is currently stored in the same directory.

Your solution works great, thank you!

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1333 9 years ago
Archive · by Muut Archive, 9 years ago
2 924 9 years ago
Archive · by Muut Archive, 9 years ago
2 4055 9 years ago
Archive · by Muut Archive, 9 years ago
1 2933 9 years ago
Archive · by Muut Archive, 9 years ago
3 1110 9 years ago