Skip to content
Grav 2.0 is officially stable. Read the announcement →
Themes & Styling

Processing Twig in Page Frontmatter?

Solved by Paul Hibbitts View solution

Started by Paul Hibbitts 9 years ago · 1 replies · 1477 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 Sebadamus, 7 days ago
5 148 15 hours ago
Themes & Styling · by martynfoster735, 1 week ago
1 193 1 week ago
Themes & Styling · by Justin Young, 3 weeks ago
1 241 3 weeks ago
Themes & Styling · by Slebeig, 1 month ago
4 376 1 month ago
Themes & Styling · by Pedro M, 3 months ago
4 745 3 months ago