Render Variables in Frontmatter Header

Is it possible to have Twig render a variable, which is defined in user/config, inside a .md header?

For example:

      category: 'foobar'
      exhibition: {{ site.config.exhibition_id }}

I enabled

    markdown: true
    twig: true

but this didnt help. I keep getting this error:

Unexpected characters near "}"...

Having exactly the same issue… when you use open graph I would like to access the images.

There’s no indication in the documentation that this is possible. Your twig files already have access to {{site.config.*}}, though. Plugins like Import and Header by Taxonomy can inject page headers.

If you can explain more about your use case, maybe we can help you find another way to accomplish it? You can always file an issue as well. Maybe it’s something the developers can accommodate.

Try changing this in your user/config/system.yaml:

It’s an option that lets you process Twig in frontmatter :slight_smile:

Thanks a lot for all the help!
I managed to get it working using the tip from rhukster:

    process_twig: false
    ignore_fields: ['form','forms']

However, its important to note: When using a Twig Variable it must be quoted.

This does not work:

menu: {{ page.title }}

But this version works fine:

menu: '{{ page.title }}'


Obviously it is:

    process_twig: true

I tried

   'og:image' '{{['title_image'].url }}'

but it wouldn’t show up… If i use page.header.title instead, the meta data is showing up. Does it mean I can’t access the in frontmatter?

You could try replacing the single quotes around title-image by double quotes so['title_image'] becomes["title_image"], in order not to confuse the parser.

@bleutzinn: Thx, tried it, but still it won’t show up…

Is title_image the full filename of your image or does it have a filename extension such as .png? If so you need to specify["title_image.png"].

You still have the problem with the internal quotes. You still need to alternate single and double quotes. There are numerous online YAML validators. Try copying your header into one of those and make sure your YAML is valid.

I don’t know if it’s a typo, but you forgot the : between ‘og:image’ and '{{[‘title_image’].url }}'
This below should work:

'og:image' : '{{['title_image'].url }}'

Btw, I noticed that in frontmatter, it looks like[image.jpg].url(true) does not output the absolute url of the image, I had to force it with

{{ base_url_absolute }},{{[''myimage.png''].url(true) }}

@paulmassendari: Thanks, that’s working!