Things I have tried
I searched google, the community plugins, and the forums
What I’m trying to do
Firstly, I’m new to this, so it’s totally possible that I’m using templater wrong and I’m missing the right way to do what I’m trying to.
I’m a developer, and have worked with jinja2 templates for a long time. They’re very powerful, easily extendable, they mostly look good, and it’s better suited to rendering text than javascript as templater uses.
I’m extremely surprised to see there’s not one plugin that allows one to use jinja templates.
The things that bother me from templater might sound silly, but… hey, I think we’re all a bit obsessive, otherwise we wouldn’t be using Obsidian, would we?
Here’s an example:
To generate a contact’s metadata I’ve got the following (abridged, the rest doesn’t matter):
let name = await tp.system.prompt("name");
names = name.split(" ")
let firstName = names[0]
let lastName = names[1]
let team = await tp.system.prompt("Team");
-%>
---
aliases:
- <% firstName + " " + lastName %>
- <% lastName + " " + firstName %>
- <% firstName + "." + lastName %>
created: "{{date}} {{time}}"
tags:
- person
<% team ? "team: " + team : "" %>
---
There’s several things that bother me from that.
- Firstly, the ternary operator (that
team?"team":""
thing) is ugly and hard to read - secondly having to concatenate values like that with
+
is also ugly and hard to read - thirdly, if there’s no team, an empty line will be added to the file, and the only way around it I could find would be to change that line to:
<%- team ? "\nteam: " + team : "" %>
or similar.
For comparison, an equivalent template in jinja (leaving aside the fact that it doesn’t have capabilities to call on system.prompt
and that kind of stuff, which I think is great) would look like:
---
....
tags:
- person
{%- if team %}
team: {{team}}
{%- endif %}
---
So, is there any way of conditionally adding lines like that on templater, or any plugins to use jinja, or anything else I’m missing?
Thanks for the help
Tomas