Retrieving yaml properties inside a note

I have been trying to use a template assigned to a directory via templater settings that includes a piece of code to read a frontmatter YAML property named “PROJ_NAME”

The end goal is to use the template to create daily logs for a project. As part of the project folder setup I intend to place the template inside the Daily Log directory and assign that temple to that directory.

I then edit the template and assign a value to the PROJ_NAME YAML property of “Project xyz”

The template will also include navigation links (PREV and NEXT) that will parse the file name based on the PROJ_NAME and the file Date to view previous or next daily log in the directory.

The problem is when the files are created the YAML call to retrieve the PROJ_NAME value returns “undefined”.

I have looked at the templater documentation and have the template setup as follows:


PROJ_NAME: Project XYZ
Status:

// test case just to see if I can retrieve the value to use for file name parsing
<% tp.frontmatter.PROJ_NAME %>

I cannot get this to work, I have tried other variations but no luck so far.

The only way I have been able to retrieve the YAML property is as follows:

PROJECT NAME: $= dv.current().PROJ_NAME

I have seen this same question posted elsewhere in this same forum with no solid solution showing how to do it using the format posted in the templater documentation.

This solution involves using variables:
McAfee Web Gateway - Notification

THIS THREAD VIEWS IT AS A BUG THEN SOMEONE CLOSES IT STATING IT IS WORKING AS IT IS INTENDED TO WORK, uuummm not for me :), they didn’t ask me to close it :slight_smile: jk

Can anyone explain to me why this is not working as shown in the templater documentation?
Or am I misunderstanding something?

In the last thread I provided the link too it was almost like the one who closed the case was indicating you do not access the YAML in the note body in the active file as you have access to the YAML itself (viewing anyway)

Thanks in Advance
-Tim C.

Your syntax works in a local test vault:

<% tp.frontmatter.PROJ_NAME %>

templater

What does the YAML header look like in source mode? What type of property is assigned to the key–value pair?

Hmmm, I was able to get it to work the way you did by INSERTING a template into the active file.

I was thinking that if the <% tp.frontmatter.PROJ_NAME %> was in an existing template that it would be populated when a file was created from the template. I was not aware that it only works when a template is inserted into an active file.

Thank for pointing that out, I would have never performed that, as that is not my typical work-flow. I like to used pre-defined templates to create notes.

-Tim C.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.