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

Can I reference variables within my page markdown files?

Started by William Saxton 9 years ago · 2 replies · 3146 views
9 years ago

Let's say I have my company name/phone # stored in my config file:

/usr/config/themes/mytheme.yaml:

YAML
company_name: XYZ Builders
contact_phone_no: (123) 456-7890

Is there a way of accessing this within my markdown? I know this isn't twig, but how can I get something like this to work:

default.md

TWIG
Welcome to the home page of {{ company_name }}!  
If you have any questions, please contact us at: {{ contact_phone_no }}.

Also, bonus points if there is a better place to put this other than in side of my custom theme's config file (ie user/config/site.yaml or somewhere else).

9 years ago

As you suggest, site.yaml would be the better place as this is site-specific information, not theme-specific. Further, you can render Twig in Markdown with:

YAML
---
title: Home
process:
  twig: true
---

And then render it with {{ site.company_name }}.

👍 1

Suggested topics

Topic Participants Replies Views Activity
Content & Markdown · by Jochen, 8 months ago
6 93 8 months ago
Content & Markdown · by Ton Haarmans, 1 year ago
10 183 1 year ago
Content & Markdown · by Jan L'Am, 1 year ago
4 145 1 year ago
Content & Markdown · by Leonardo, 1 year ago
3 58 1 year ago
Content & Markdown · by belthasar, 1 year ago
4 253 1 year ago