Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Processing Twig in Page Frontmatter?

Solved by Paul Hibbitts View solution

Started by Paul Hibbitts 9 years ago · 1 replies · 1701 views
9 years ago

I've set the following in my site.yaml file:

YAML
frontmatter:
process_twig: true

And am trying to calculate the URL for an image for Twitter Card data:

TXT
metadata:
'twitter:card' : summary
'twitter:site' : @hibbittsdesign
'twitter:title' : CMPT-363 Week 2 (Sep 13 - 19)
'twitter:description' : Week 2 Materials for CMPT 363 User Interface Design at Simon Fraser University
'twitter:image': page.media.images|first.absolute_url

However, the above does not work and if I add brackets, like this:

TWIG
'twitter:image': {{ page.media.images|first.absolute_url }}

I get a Twig error, any ideas on if/how this could be done?

Thanks very much,
Paul

last edited 09/08/17 by Paul Hibbitts
9 years ago Solution

So, I've discovered two things: one is that this processing happens before page processing so I cannot use page functions, however I also learned how to make this work otherwise!

You need to include quotes around the Twig code, so for example:

TWIG
    'twitter:image':  '{{ base_url_absolute }}{{ page.find(''/headerimage'').media.images|first.url(true) }}'

Also notice that if you need to use quotes in the Twig line itself, you need to double quote them.

👍 2

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by MarkP, 2 weeks ago
3 193 2 weeks ago
Themes & Styling · by TomW, 2 weeks ago
0 111 2 weeks ago
Themes & Styling · by themetman, 3 weeks ago
1 206 3 weeks ago
Themes & Styling · by AH, 1 month ago
1 324 3 weeks ago
Themes & Styling · by Bruno, 4 years ago
6 1523 3 weeks ago