Need help with Tempater Code to Retrieve and load a YAML

What I’m trying to do

I am attempting to use a hybrid of Templater and Dataview code to retrieve a YAML value from a file called “PROJ_INFO” from the parent directory of the current note. I am attempting to retrieve two YAMLS “PROJ_ID” and “PROJ_NAME”

Things I have tried

Here is the current code set I have been experimenting with but it comes back with an error stating “PROJ_NAME” is undefined. I am hoping someone sees something I may be overlooking.

// Get current file’s path and move up one folder
const fullPath = tp.file.path().split(“/”);
fullPath.pop(); // Remove current filename
fullPath.pop(); // Go up one folder
const parentFolder = fullPath.join(“/”);
const projectInfoPath = parentFolder + “/PROJ_INFO.md”;

tR += **Debug Info:** Recognized projectInfoPath → \${projectInfoPath}`\n; console.log(Debug Info: Recognized projectInfoPath → ${projectInfoPath}`);

// Check if dv (Dataview API) is available
if (typeof dv === “undefined”) {
tR += “:x: Error: Dataview plugin not available.\n”;
} else {
// Correct usage: vault-relative string, not wikilink
const projectInfo = dv.page(projectInfoPath);

if (!projectInfo) {
tR += ❌ Could not load PROJ_INFO.md at: \${projectInfoPath}`\n`;
} else {
const projName = projectInfo.PROJ_NAME || “:warning: PROJ_NAME not found”;
const projID = projectInfo.PROJ_ID || “:warning: PROJ_ID not found”;

tR += `✅ Loaded from: \`${projectInfoPath}\`\n`;
tR += `**Project Name:** ${projName}\n`;
tR += `**Project ID:** ${projID}\n`;

}
}

If by YAML you mean the value of a key stored in the frontmatter/Properties of a note, maybe this snippet could potentially help you :woman_shrugging: : Retrieve frontmatter from another note (Zachatoo)

Edit: because I forgot to mention this but tp.file.path(), as written, returns the full absolute path to the file on your system not just the path of the file relative to the vault :blush: , that would be tp.file.path(true).

Now, if you just want the parent folder, you might want to take a look at tp.file.folder(true) :blush:

1 Like

I will be on travel for a couple days, I will look at this when I get back.
Thanks fo rthe link