Dynamic Transclusion

I have a Weekly Journal / Recap template.

In this my hope is for it to pull the contents of my daily journal using Transclusion.

In this way, when I write my Weekly Journal entry, I’m not forced to go and copy/paste each of my Daily Journal entries into the Weekly Journal – it simply shows the daily entries there automatically.

To achieve this, I’m using the Templater plugin which allows me to use:
<%+ tp.date.now("YYYY-MM-DD") %>
This expresses as: 2023-05-22

If I then instead use:
![[<%+ tp.date.now("YYYY-MM-DD", -6) %>]]
My hope was that the weekly note would look for a note named: “2023-05-22” and show it’s contents using Transclusion

When I switch to reading mode, it does in fact say: “2023-05-16” is not created yet. Click to create."

This to me looks like success! Because I figured that if I simply had a note named “2023-05-22” it would show it’s contents.

However, when I created such a note, it still showed “2023-05-16” is not created yet. Click to create." and when I clicked it, it instead tried to create a new note with the title: “<%+ tp.date.now(“YYYY-MM-DD”) %>”

Is this achievable?

TLDR:
Is dynamic transclusion possible?

Wow, I really appreciate your detailed answer.

I did however have trouble implementing it, I even took your description and my question to ChatGPT to try to make sense of why it isn’t working.

The first problem I have I suppose is that we’re doing the opposite of one another.

I’d like to have a Weekly Journal Template which creates me a Weekly Journal entry titled in the 2023-W20 format, which automatically transcludes the entire Daily Journal for every day within that week, so 2023-05-15 through 2023-05-21.

My thinking of how it would work, is that when I create the Weekly Journal, the code will look at the title, being “2023-W20” and then calculate the seven required transclusions, and they’d need to be formatted as: “![[2023-05-15]]” and so on.

However, in an effort to try to better understand your way of doing things, I tried to replicate your method verbatim and came across an error, which stated:

" <% moment (tp. file.title, ‘yyyy-MM-dd’).startOf(‘week’).format(‘999g-[W]ww’)
%>#Aandachtspunten <% moment(tp. file.title, ‘yyyy-MM-dd’).startOf(‘week’).format(‘gggg-
[Www’) %>" is not created yet. Click to create.

This is probably just a forum typo or otherwise doesn’t matter, but if you did exactly as you described, you created a note with the wrong date — 2023-05-22 instead of 2023-05-16.

What you want to do should be possible. I used to do something similar with the Periodic Notes plugin instead of Templater. Unfortunately I don’t know Templater well enough to help.

I think a problem you are having is you are using dynamic templater commands whereas you should be using execution commands instead. That way when you create your weekly note it will actually insert the text rather than just displaying it to you.

I do the same thing in my weekly journal. I can add an example later to show you how I manage it if you still need the help.

Edit: here is a good example: Structured daily/weekly notes - in Obsidian - DEV Community

1 Like

To further exoand upon the last response; Templater works in three different modes, and this is controlled by the leading characters of your template block:

  • <% – The normal variant, which I think you should be using on this case. Here the template will be replaced when you insert the template (or create a file based upon the template)
  • <%+ – This kind of template blocks are kept as is into the resulting file, and are expanded when you enter reading mode (and not live-preview). Doing this within a link text, is somewhat sketchy and can result in malformations like you’ve already experienced.
  • <%* – This kind of blocks are used when you end want to execute arbitrary javascript code. These blocks are also expanded when inserting or creating a file based upon your template. To get output from these blocks, you can assign text to the tR variable.

So remove the plus sign from your template, and most likely it should work just nicely, and you’ll embed your daily notes from that weekly summary.

1 Like

My man! Thank you so much!

The link you shared lead me down a path which has landed me SUPER close to my ideal outcome.

I was hoping to lean on you or anyone else here, for one final refinement.

The code I’m using :

As you can see in the screenshot below, the code I’m using is working perfectly except that it’s titling each section with “Monday” instead of providing the correct day of the week, for the subsequent block.

Are you able to see where I’ve gone wrong?

The {{date}} format is using the default template style of getting today’s date, it’s not using the date variable you defined above.

What you want is to use templater again:

tR += `### ${tp.date.weekday("dddd", i, tp.file.title, "YYYY-[W]W"}`

(didn’t test that, but it should give you what you want)

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