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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Themes & Styling

Processing Twig in Page Frontmatter?

Solved by Paul Hibbitts View solution

Started by Paul Hibbitts 9 years ago · 1 replies · 1336 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 Pedro M, 2 months ago
4 193 2 months ago
Themes & Styling · by Ian, 2 months ago
3 91 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 451 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 45 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 125 3 months ago