Avoid empty linebreaks in Daily Notes Lists in Obsidian

Posted by ads on Friday, 2024-08-02
Posted in [Obsidian][Software]

In my Daily Notes in ObsidianMD I want to add entries on certain weekdays. However this added empty lines in-between. Figuring out what is going on in the Template takes some time and effort.

Daily Notes in ObsidianMD

I’m using ObsidianMD literally daily in my life. One of the heavily used features are the Daily Notes. I’m also using the Templater plugin by SilentVoid13 to prepare a template for every Daily Note.

Part of my weekly routine is posting an interview with a PostgreSQL Person of the Week. You can find the interviews here, usually posted on Monday. And one Stolpersteine posting every Tuesday. In my Daily Notes I keep track of which blog posting I published on that day.

Wouldn’t it be nice to have a ready-to-go text on Mondays and Tuesday added to the Markdown in my Daily Notes? Something like:

1
2
3
4
5
## What happened today?
- Blog Posting PostgreSQL Person of the Week:
  - ...
- Blog Posting Stolpersteine:
  - ...

But only on Mondays respectively Tuesdays, of course!

Turns out that is complicated!

I started with the following Templater code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## What happened today?
<%*if (tp.date.now("dddd") == "Monday") {%>
- Blog Posting PostgreSQL Person of the Week
  -
<%*} %>
<%*if (tp.date.now("dddd") == "Tuesday") {%>
- Blog Posting Stolpersteine
  -
<%*} %>
-

But this resulted in a rather unaesthetic empty line after the header (for Tuesdays in this exampple):

1
2
3
4
5
## What happened today?
  <-- empty line
- Blog Posting Stolpersteine
  -
-

Unlike Jinja2 in Ansible, which has powerful whitespace control, the Templater filter in ObsidianMD has no such feature. It comes down to placing the Templater code and the output exactly where it’s needed, including a start after the header line and no unnesessary line breaks.

Here is the resulting code after much trial and error:

1
2
3
4
5
6
## What happened today?<%* if (tp.date.now("dddd") == "Monday") { %>
- Blog Posting PostgreSQL Person of the Week:
  - <%* } if (tp.date.now("dddd") == "Tuesday") { %>
- Blog Posting Stolpersteine:
  - <%* } %>
-

As you can see, the Templater code starts right at the end of the header line. Starting it on the next line results in the empty line we’ve seen before. There are only line breaks which appear in the output. Everything else is basically “one line of code”. It looks rather ugly, and I don’t like it.

But it does the job:

1
2
3
4
## What happened today?
- Blog Posting Stolpersteine:
  -
-

Header image

Base image by Anete Lusina, additions and modifications by me.


Categories: [Obsidian] [Software]

Comments

With an account on the Fediverse or Mastodon, you can respond to this post. Known replies are displayed below:



Note: This will load data from mastodon.social.

Learn how this is implemented here.


Share: