Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

Image Assets in .md header

Started by Muut Archive 11 years ago · 2 replies · 344 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 2280 9 years ago
Archive · by Muut Archive, 9 years ago
2 1496 9 years ago
Archive · by Muut Archive, 9 years ago
2 4745 9 years ago
Archive · by Muut Archive, 9 years ago
1 3559 9 years ago
Archive · by Muut Archive, 9 years ago
3 1621 9 years ago