%% date:: [[2024-01-26]] parent:: %% # [[Templater plugin]] Obsidian Templater is a [[Obsidian Plugins|plugin]] for [[Obsidian]] that extends upon the Core plugin, confusingly called _Templates_. TemplateR increases the options for creating templates, adds the ability to set default templates per directory, and even runs JavaScript within a vault. ![](https://youtube.com/5j9fAvJCaig) ![](https://youtu.be/SUzRlhKFCYM) ## Examples of Templater Usage ### Get a frontmatter property value ``` <% tp.frontmatter["type"] %> ``` Replace `type` with the name of the parameter in your YAML frontmatter. This template, when executed, will be replaced with the value of the specified property. ### Create a prompt to enter a value Here's the frontmatter for a book review template I use: ``` --- date: [[<% tp.date.now("YYYY-MM-DD") %>]] Author: "[[<% tp.system.prompt("Author's name", "") %>]]" --- ``` The Templater string in the `Author` property creates a dialog box when this template is applied: ![[templater-authors-name.png]] Typing `Nicole van der Hoeven`, for example, adds that as a linked property value within the frontmatter: ![[templater-author-property-value-linked.png]] ### Choose from a list the `tp.system.suggester()` function lets you choose from several topics. Here's something that lets you choose between multiple statuses: ``` Status:: <% await tp.system.suggester(["Awaiting Funding", "Not Fulfilled", "Partially Fulfilled", "Fulfilled"], ["Awaiting Funding", "Not Fulfilled", "Partially Fulfilled", "Fulfilled"]) %> ``` Here's what that looks like when the template is applied: ![[templater-status-selection.png]] ### Create a new file within this folder Creates a file (and, optionally, a folder) within the current directory. ``` <%* await tp.file.create_new("This is a new file", "testfolder/Testfile") %> ``` The above function will create a folder named `testfolder` inside the current folder, and then a file named `Testfile` inside that new folder. (Thanks to Patreon Carlos M. for asking this question!) ### Automatically move notes using a certain template to a folder Go into Templater settings and set a Folder Template. For example, set any new note created from a note in `/Meetings/` to automatically use `templates/Person`. In `templates/Person.md`, include the following line: ```js <% await tp.file.move("/private/People/" + tp.file.title) %> ``` When the template is applied to a note, the note will not only take the `Person` template; it'll also automatically be moved to the `People` folder instead of the `Meetings` one. ### Get next Wednesday's date This string returns the date of the next specified day of the week, in this case Wednesday: ``` <% tp.date.weekday("YYYY-MM-DD", 10) %> ``` When applied, and assuming today is 2024-01-26, the string above changes to: ``` 2024-01-31 ``` You can change the `10` in the Templater string to change the day of the week. Here's how the days of the week map: | Index | Day | | ---- | ---- | | 0 | this week's Sunday | | 1 | this week's Monday | | 2 | this week's Tuesday | | 3 | this week's Wednesday | | 4 | this week's Thursday | | 5 | this week's Friday | | 6 | this week's Saturday | | 7 | next week's Sunday | | 10 | next week's Wednesday | | 17 | second Wednesday from now | | 31 | fourth Wednesday from now | ## Use cases - Video templates: [[My workflow for making videos with Obsidian]]