# Obsidian Templater Plugin | | url:: [Obsidian Templater Plugin](https://github.com/SilentVoid13/Templater) | | ---- | ---- | | | docs:: [Introduction - Templater](https://silentvoid13.github.io/Templater/) | ## Run plugin command from a template ```js %% Get commands so you can get the id: %% app.commands.commands ``` ```js app.commands.executeCommandById(_) ``` ```js app.commands.executeCommandById("obsidian-wikipedia:wikipedia-get-active-note-title") ``` `app.workspace.activeLeaf.view.file` ## Manual pause, sleep, timeout, setTimeout ``` ``` ## Run user script You can define a templater user function that is bound to a local script. E.g., with that, then you can run whatever your system can run: - [[Python]] - [[JavaScript]] - [[Shell]] - [[AppleScript]] - System keyboard shortcuts to launch another program like [[Keyboard Maestro]] ## Update existing note's yaml/properties - [New Properties and templater prompts and commands? - Help - Obsidian Forum](https://forum.obsidian.md/t/new-properties-and-templater-prompts-and-commands/66425/13) ``` <%* setTimeout(() => { app.fileManager.processFrontMatter(tp.config.target_file, frontmatter => { // Update or add as many fields as you want frontmatter['Some property'] = 'Some value' frontmatter['Another property'] = 'Some other value' // You can even remove properties if you want delete frontmatter['Unwanted property'] }) }, 200) // the reason for the timeout is to let the template complete first -%> ``` ## Do something after all templates have finished running [tp.hooks - Templater](https://silentvoid13.github.io/Templater/internal-functions/internal-modules/hooks-module.html) ## Other objects and functions available [tp.obsidian - Templater](https://silentvoid13.github.io/Templater/internal-functions/internal-modules/obsidian-module.html) `app.vault.getAllLoadedFiles()` `tp.obsidian.htmlToMarkdown("\<h1>Heading\</h1>\<p>Paragraph\</p>")` ``` // HTTP request <%* const response = await tp.obsidian.requestUrl("https://jsonplaceholder.typicode.com/todos/1"); tR += response.json.title; %> ``` file. - path - parent - name - extension - basename ## Originating (From) File, eg. like Note Refactor Plugin `Originating file: <% tp.config.active_file.basename %>` `Link to that file: [[<% tp.config.active_file.path %> | My parent ]]` ``` <%* let last_file = "" let recent_leaf = this.app.workspace.getMostRecentLeaf(); let back_history = recent_leaf.history.backHistory; %> ``` ## tR var > Sometimes, you may want to output something when using a JS execution command. > > When our templating engine generates a replacement string using all of our commands results, it is stored in a variable named tR. This is the string that will contain the processed file content. You are allowed to access that variable from a JS execution command. > > This means that, to output something from a JS execution command, you just need to append what you want to output to that tR string variable. > > For example, the following command: <%* tR += "test" %> will output test.