Obsidian: Templater Converters30 Jan 2024
This post is, in a sense, a natural follow up to my Path-based Commands in Obsidian post from around this time last year. In that post I demonstrated how you could trigger command line tools from within Obsidian using the Templater plugin. In this post I’m flipping that around, and rather than going external, I am focusing on the internal. The text within an Obsidian note. However, rather than adding new content, I am going to tell you a little about how I am also using Templater to convert existing content, transforming it in a variety of ways to effectively build my own text processing functionality within Obsidian.
If you have not already installed and set up the Templater plugin, then it would be worth while doing so before continuing.
Simple text in a Templater template (a Markdown file) will output the same text when the file is processed as a template for insertion. There is however a syntax to run sets of code that will then generate dynamic content to include in the template.
The execution of dynamic content is a key requirement of Templater to allow us to dynamically process content.
The Basic Principle
tp is the Templater object,
file refers to the current Markdown file in Obsidian, and
A Simple Example
toUpperCase) to help us with that, and we can create a template like this.
<% tp.file.selection().normalize().toUpperCase() %>
The selected text when the template is invoked is converted to upper case, and then placed back into the Obsidian note, replacing the selection.
The Template Collection
I have gathered and commented thirty conversion templates to share with everyone, and I expect to add more over time. You can download these templates from a GitHub repository I created to host them:
The repository provides some guidance on how to ‘install’ the templates, and also explains a little bit more of my particular set up for them, such as why they have what might appear to be an unusual prefix for the template file names.
Frequent Use Conversions
Triggering templates from the command palette is very useful, but sometimes you may find you would rather have a quicker way of triggering it because you use it so frequently. Arguably the best way to speed things up is to trigger the template via a keyboard shortcut. The Hotkeys for Templates plugin allows you to do just that.
Doing this can make the templates feel even more like built in commands, so if there are ones you use frequently it is worth consideration.
Templater is one of the most versatile plugins for Obsidian, and it is amazing how it can be used to effectively build your own functionality within Obsidian, without you having to resort to building an entire plugin. Particularly so if you want to do something relatively straight forward.
It often feels to me like Templater is a plugin through which you can build your own mini-plugins, and I hope that I continue to discover new and innovative uses through my own practice and that of others in the ever expanding Obsidian community.
If you have not already done so, please take a look through the GitHub repository and the templates it contains. I would hope that at least a few of them might be useful to you.