Use YAML Frontmatter to define variables in the md document

It would be great to use parameters from YAML Frontmatter as a parameter im Markdown documents

Example:

title: YAML Front Matter
description: A very simple way to add structured data to a page.

# {{ title }}

 {{ description }} 

Page content here...
36 Likes

Great idea. +1

I’m curious if it might break a lot of third-party plugins that already use the {{ }} syntax. If so, I’m sure that would be a bummer but still probably worth it because first party should get priority on syntax over third-party plugins.

1 Like

iA Writer uses this syntax see its docs:

---
Customer: M. Bluth
Me: Bob Loblaw
Target Date: March 8th, 2016
---

Dear [%Customer],

Thank you for your order. It has been shipped from our warehouse and you can expect delivery on [%Target Date].

Kind regards,
[%Me]
11 Likes

I would love to see support for this method as well. I use this all the time in iA Writer.

1 Like

This would be great. Variables would be a solid step toward doing system-level work with Obsidian.

1 Like

I would LOVE something like this. Is there any other way to get something similar to this working in Obsidian?

The syntax [% ] is also in Marked 2

+1. This would allow for more dynamic notes.

You can do that using either the Dataview or the Templater plugin:

---
birthday: 2000-01-01
---

# Variables from YAML

## Dataview

Birthday: `= this.birthday`

## Templater

Birthday as in YAML: <%+ tp.frontmatter.birthday %>
Birthday formatting: <%+ moment(tp.frontmatter.birthday).format("dddd, D MMMM YYYY") %>

produces:

obsidian-variables-from-yaml

8 Likes

This is because they use MultiMarkdown. That’s a feature of MMD and it is great. I do hope Obsidian gets this feature as well.

If this is implemented, would it be salutary if Obsidian parsed wikilinks within the YAML metadata?

Given Note A with these contents:

---
Relationship1: [[Note B]]
Relationship2: [[Note C]]
---

[%Relationship1]
[%Relationship2]

Note A would appear in the backlinks lists for notes B and C, and the three notes would appear connected in the node graph.

Related feature request: Allow links in YAML front matter.

As per this post, the wikilinks in the YAML header should probably be delimited with double quotation marks.

This seems very good but for me only the third synthax works. Do you have any idea why?

I have dataview and templater installed.

Here is what I see:

image

It would be nice, but maybe there needs to be an “alternate” front matter section. In case anyone doesn’t know what YAML stands for “YAML Aint Markdown Language”. YAML is managed by a standards group and is is very narrowly defined.

Barry

Interesting! Do you know if there is any possibility to now copy the displayed variable as to get a string value? For let’s say relinking the output again:

---
title: "The Hobbit"
author: "J. R. R. Tolkien"
---

# [[<%+ tp.frontmatter.title %>]] - [[<%+ tp.frontmatter.author%>]]

I know this doesn’t work like this because what you get is not a string value right?