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.

Content & Markdown

Recursion in Markdown frontmatter

Started by Raphael Haase 9 years ago · 0 replies · 1001 views
9 years ago

There seems to be an issue with recursion in resolving Twig variables in the frontmatter:

I have a hierarchy of variable from which I want to generate variables with Twig in the frontmatter so I can set the ingredients in the frontmatter und use them in the markdown with inline twig. The reason is that I need to show the whole hierarchy of variables in the text and they should be easily changeable in the future by only changing the key variables and not all the plain text / Markdown, example:

guide/default.md:

TWIG
---
title: 'Guide'
process:
    markdown: true
    twig: true
version_build: '2017-10-18-01'
version_infix: '1742'
gen_file_prefix: "gen-GEN_T{{page.header.version_infix}}_{{page.header.version_build}}"
abc_file_prefix: "{{page.header.gen_file_prefix}}-vbox-images"
abc_archive_name: "{{page.header.abc_file_prefix}}.tar.gz"
---

... further down the line:

This guide is based on the following versions / archives:
```
Gen: {{page.header.gen_file_prefix}}
  Alpha Bravo Charlie folder name: {{page.header.abc_file_prefix}}
  Alpha Bravo Charlie file name: {{page.header.abc_archive_name}}.tar.gz
```

I have also added to system.yaml:

YAML
frontmatter:
    process_twig: true

And created frontmatter.yaml with:

YAML
process:
    twig: true

My problem is that the above breaks after 2 levels of resolving the variables, i.e. the above will render to

TWIG
Gen: gen-GEN_T1742_2017-10-18-01  <-- correct, 1 level resolved
    Alpha Bravo Charlie folder name: gen-GEN_T1742_2017-10-18-01-vbox-images <-- correct, 2 levels resolved
    Alpha Bravo Charlie file name: gen-GEN_T{{page.header.version_infix}}_{{page.header.version_build}}-vbox-images.tar.gz <-- problem: recursion breaks after 2 levels, last level of variables not resolved.

Is there a way to fix this and make the variable resolution go deeper?
If not, what is a good alternative way of achieving such multiple levels of generating strings being inserted into the markdown while showing the whole hierarchy of these generated strings in the end on the page (it's a tech tutorial) and making it easy to change the "ingredients" to the hierarchy of strings, such as dates, version numbers etc.?

Suggested topics

Topic Participants Replies Views Activity
Content & Markdown · by Jochen, 8 months ago
6 97 8 months ago
Content & Markdown · by Ton Haarmans, 1 year ago
10 185 1 year ago
Content & Markdown · by Jan L'Am, 1 year ago
4 148 1 year ago
Content & Markdown · by Leonardo, 1 year ago
3 61 1 year ago
Content & Markdown · by belthasar, 1 year ago
4 255 1 year ago