Templater add YAML string property

Use Templater to add date values as string values in YAML for a monthly template

I’ve tried to use Templater, but it may be way over my head. I got this idea to use monthly notes from the periodic notes plugin and dataview table to pull all weekly notes for that month in a view that just shows a summary and a link to the note.

Now, there may be a much easier way to accomplish this, and I realized I may be chewing off too much or have overlooked how to get this to happen.

Things I have tried

I’ve attempted to understand how to use Templater at point I create a new Monthly note to provide a YAML value for the week number and year, something I can use in the Dataview table query. I got the idea from somewhere on Redit.

<%"---"%>
created: 
status: 
tags:
  - Weekly-Notes
archive: false
summary: 
month: <% tp.date.now("MM"), offset?: number|string, reference?: string, reference_format?: string) %>
year: 
week: 
<%"---"%>

I started to look here for answers and trying to understand this article Inserting templates in the YAML section doesn't work in v1.4.5 but I am lost at this point.

Any help would be appreciated. Thanks in advance.

are you wanting something like this?

<%*
// Define options for archive and status
const archiveOptions = ["true", "false"];
const statusOptions = ["Draft", "Published", "In Review", "Archived"];

// Use tp.system.suggester to let the user choose options
const archive = await tp.system.suggester(archiveOptions, archiveOptions);
const status = await tp.system.suggester(statusOptions, statusOptions);

// Other dynamic inputs
const created = await tp.date.now('YYYY-MM-DD[T]HH:mm');
const month = await tp.date.now("MM", "+30", tp.date.now("YYYY-MM-DD"), "YYYY-MM-DD");
const year = await tp.date.now("YYYY");
const week = await tp.date.now("WW");
const summary = "Add your summary"; // Static example, adjust as necessary

// Construct YAML metadata with dynamic inputs and selected options
const metaData = `---
created: ${created}
status: ${status}
tags:
  - Weekly-Notes
archive: ${archive}
summary: ${summary}
month: ${month}
year: ${year}
week: ${week}
---`;

tR += metaData;
%>

I wrote it this way because of the other post you were referring to.

1 Like

This looks complicated, I’ll need some time to review and understand to implement. As I scan what you have developed, it seems it may be what I was looking to achieve. I do hope I can get my head wrapped around it as this would be great to streamline my workflow. When every minute counts… you know what I mean… thanks!

Ok, so initially yes this works. I do believe I have much to lear from how to use or create meta data like for the month, year, and week values. I’m assuming that ${month} calls the “month” metadata field exsiting and prints the current month number.

As a side note, to add placeholder text asking questions, two of the lines could be adjusted to be:

tp.system.suggester(archiveOptions, archiveOptions, false, "Archive this note?");
const status = await tp.system.suggester(statusOptions, statusOptions, false, "What's the status?");
1 Like

This worked beautifully, I never new there was such a thing that could be done as a tp.system.suggester(), in fact I didn’t know half of what is being shown here between you and @Kinder was even possible in Obsidian!

I’ll keep playing around with this for weekly, monthly, meeting, and action or project type notes. I can see that I can have much more control over automating than I thought was possible.

I’ll post my results soon.

Note for others, when attempting to add options for backlinks I’ve found that this needs to be handled differently. This came from when I was thinking how to create a “suggester” options list that I could reference any file that was tagged “Focus.” (I haven’t figure that out. Above my abilities)

I found this works for when you just have one person to mention, not sure how this could be possible with multiple persons.

// obviously there would be more constants than just "attendees," and for those like me, these are values from the YAML or metadata
const attendees = "person's name"

// you'll see to include a link to another note/file it must be within single-quotations and then within double brackets
const metaData = `---
attendees: '[[$attendees}]]'
---`

Note: if the link you reference using this method doesn’t exist you can click on the link to create it.

You could create a list of options I suspect, but not sure how this would work with getting the output to create backlinks.