### All web module examples combined Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/web-module.html A combined example showing all three web module functions: daily_quote, random_picture, and request. This is the final example block on the page. ```templater // Daily quote <% await tp.web.daily_quote() %> // Daily quote in Spanish <% await tp.web.daily_quote("es") %> // Random picture <% await tp.web.random_picture() %> // Random picture with size <% await tp.web.random_picture("200x200") %> // Random picture with size and query <% await tp.web.random_picture("200x200", "landscape,water") %> // Simple request <% await tp.web.request("https://jsonplaceholder.typicode.com/todos/1") %> // Request with path <% await tp.web.request("https://jsonplaceholder.typicode.com/todos", "0.title") %> ``` -------------------------------- ### tp.date.now usage examples Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/date-module.html Examples showing how to retrieve the current date with various formats, offsets, and reference dates. ```javascript // Date now <% tp.date.now() %> // Date now with format <% tp.date.now("Do MMMM YYYY") %> // Last week <% tp.date.now("YYYY-MM-DD", -7) %> // Next week <% tp.date.now("YYYY-MM-DD", 7) %> // Last month <% tp.date.now("YYYY-MM-DD", "P-1M") %> // Next year <% tp.date.now("YYYY-MM-DD", "P1Y") %> // File's title date + 1 day (tomorrow) <% tp.date.now("YYYY-MM-DD", 1, tp.file.title, "YYYY-MM-DD") %> // File's title date - 1 day (yesterday) <% tp.date.now("YYYY-MM-DD", -1, tp.file.title, "YYYY-MM-DD") %> ``` -------------------------------- ### Moment.js integration examples Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/date-module.html Examples demonstrating direct usage of the moment object for advanced date manipulation. ```javascript // Date now <% moment(tp.file.title, "YYYY-MM-DD").format("YYYY-MM-DD") %> // Get start of month from note title <% moment(tp.file.title, "YYYY-MM-DD").startOf("month").format("YYYY-MM-DD") %> // Get end of month from note title <% moment(tp.file.title, "YYYY-MM-DD").endOf("month").format("YYYY-MM-DD") %> ``` -------------------------------- ### Prompt examples with tp.system.prompt() Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/system-module.html Spawns a prompt modal and returns user input. Examples show basic prompt, default value, multiline, pre-selected default, and reusing the output. ```templater // Prompt <% await tp.system.prompt("Please enter a value") %> // Prompt with default value <% await tp.system.prompt("What is your mood today?", "happy") %> // Multiline prompt <% await tp.system.prompt("What is your mood today?", null, false, true) %> // Prompt with pre-selected default value <% await tp.system.prompt("What is your mood today?", "Input a mood...", false, false, true) %> // Reuse output from prompt <%* let value = await tp.system.prompt("Please enter a value"); %> # <% value %> selected value: <% value %> ``` -------------------------------- ### Example frontmatter file with alias and note type Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/frontmatter-module.html Example frontmatter block showing a file with `alias` and `note type` variables. This is used with the following template example. ```yaml --- alias: myfile note type: seedling --- file content ``` -------------------------------- ### Multi-suggester examples with tp.system.multi_suggester() Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/system-module.html Spawns a suggester prompt supporting multiple selections. Examples show basic usage, mapping function, file selection, tag selection, reusing the selected values, and setting default values. ```templater // Multi-suggester <% await tp.system.multi_suggester(["Happy", "Sad", "Confused"], ["Happy", "Sad", "Confused"]) %> // Multi-suggester with mapping function (same as above example) <% await tp.system.multi_suggester((item) => item, ["Happy", "Sad", "Confused"]) %> // Multi-suggester for files <% (await tp.system.multi_suggester((item) => item.basename, tp.app.vault.getMarkdownFiles())).map(f => `[[${f.basename}]]`) %> // Multi-suggester for tags <% await tp.system.multi_suggester(item => item, Object.keys(tp.app.metadataCache.getTags()).map(x => x.replace("#", ""))) %> // Reuse value from multi-suggester <%* let selectedValues = await tp.system.multi_suggester(["Happy", "Sad", "Confused"], ["Happy", "Sad", "Confused"]); %> # <% selectedValues %> selected values: <% selectedValues %> // Default value for the suggester <%* let selectedValue = await tp.system.multi_suggester(["Happy", "Sad", "Confused"], ["Happy", "Sad", "Confused"], false, "", undefined, ["Happy", "Confused"]); %> # <% selectedValue %> selected value: <% selectedValue %> ``` -------------------------------- ### tp.date.tomorrow usage examples Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/date-module.html Examples showing how to retrieve tomorrow's date with default and custom formats. ```javascript // Date tomorrow <% tp.date.tomorrow() %> // Date tomorrow with format <% tp.date.tomorrow("Do MMMM YYYY") %> ``` -------------------------------- ### tp.file.create_new - File creation examples Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/file-module.html Creates a new file with specified content or template. Options include filename, open_new, and folder. The last example appends a link to the created file. ```templater // File creation <%* await tp.file.create_new("MyFileContent", "MyFilename") %> // File creation with template <%* await tp.file.create_new(tp.file.find_tfile("MyTemplate"), "MyFilename") %> // File creation and open created note <%* await tp.file.create_new("MyFileContent", "MyFilename", true) %> // File creation in current folder <%* await tp.file.create_new("MyFileContent", "MyFilename", false, tp.file.folder(true)) %> // File creation in specified folder with string path <%* await tp.file.create_new("MyFileContent", "MyFilename", false, "Path/To/MyFolder") %> // File creation in specified folder with TFolder <%* await tp.file.create_new("MyFileContent", "MyFilename", false, tp.app.vault.getAbstractFileByPath("MyFolder")) %> // File creation and append link to current note [[<% (await tp.file.create_new("MyFileContent", "MyFilename")).basename %>]] ``` -------------------------------- ### tp.date.weekday usage examples Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/date-module.html Examples showing how to retrieve specific weekdays relative to today or a reference date. ```javascript // This week's Monday <% tp.date.weekday("YYYY-MM-DD", 0) %> // Next Monday <% tp.date.weekday("YYYY-MM-DD", 7) %> // File's title Monday <% tp.date.weekday("YYYY-MM-DD", 0, tp.file.title, "YYYY-MM-DD") %> // File's title previous Monday <% tp.date.weekday("YYYY-MM-DD", -7, tp.file.title, "YYYY-MM-DD") %> ``` -------------------------------- ### tp.date.yesterday usage examples Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/date-module.html Examples showing how to retrieve yesterday's date with default and custom formats. ```javascript // Date yesterday <% tp.date.yesterday() %> // Date yesterday with format <% tp.date.yesterday("Do MMMM YYYY") %> ``` -------------------------------- ### Conditional and function examples for JavaScript execution Source: https://silentvoid13.github.io/Templater/commands/execution-command.html A collection of JavaScript execution command examples showing conditional output based on file title, frontmatter, and tags, a custom logging function, and replacing text in file content. ```javascript <%* if (tp.file.title.startsWith("Hello")) { %> This is a hello file ! <%* } else { %> This is a normal file ! <%* } %> <%* if (tp.frontmatter.type === "seedling") { %> This is a seedling file ! <%* } else { %> This is a normal file ! <%* } %> <%* if (tp.file.tags.contains("#todo")) { %> This is a todo file ! <%* } else { %> This is a finished file ! <%* } %> <%* function log(msg) { console.log(msg); } %> <%* log("Title: " + tp.file.title) %> <%* tR += tp.file.content.replace(/stuff/, "things"); %> ``` -------------------------------- ### Prompt: Basic, Default, Multiline, Pre-selected, Reuse Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/system-module.html Examples of tp.system.prompt for user input. Includes basic prompt, default value, multiline, pre-selected default, and reusing the output. ```templater <% await tp.system.prompt("Please enter a value") %> ``` ```templater <% await tp.system.prompt("What is your mood today?", "happy") %> ``` ```templater <% await tp.system.prompt("What is your mood today?", null, false, true) %> ``` ```templater <% await tp.system.prompt("What is your mood today?", "Input a mood...", false, false, true) %> ``` ```templater <%* let value = await tp.system.prompt("Please enter a value"); %> # <% value %> selected value: <% value %> ``` -------------------------------- ### Valid invocations of tp.date.now Source: https://silentvoid13.github.io/Templater/syntax.html Examples of valid invocations for tp.date.now, demonstrating various argument combinations. The last example assumes the file name is in the format YYYY-MM-DD. ```plaintext <% tp.date.now() %> ``` ```plaintext <% tp.date.now("YYYY-MM-DD", 7) %> ``` ```plaintext <% tp.date.now("YYYY-MM-DD", 7, "2021-04-09", "YYYY-MM-DD") %> ``` ```plaintext <% tp.date.now("dddd, MMMM Do YYYY", 0, tp.file.title, "YYYY-MM-DD") %> ``` -------------------------------- ### Output of the note method call Source: https://silentvoid13.github.io/Templater/user-functions/script-user-functions.html The output produced by the previous example, showing the formatted callout. ```markdown > [!note] > Line 1 > Line2 ``` -------------------------------- ### Combined date module examples Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/date-module.html A consolidated list of various date module function calls. ```javascript // Date now <% tp.date.now() %> // Date now with format <% tp.date.now("Do MMMM YYYY") %> // Last week <% tp.date.now("YYYY-MM-DD", -7) %> // Next week <% tp.date.now("YYYY-MM-DD", 7) %> // Last month <% tp.date.now("YYYY-MM-DD", "P-1M") %> // Next year <% tp.date.now("YYYY-MM-DD", "P1Y") %> // File's title date + 1 day (tomorrow) <% tp.date.now("YYYY-MM-DD", 1, tp.file.title, "YYYY-MM-DD") %> // File's title date - 1 day (yesterday) <% tp.date.now("YYYY-MM-DD", -1, tp.file.title, "YYYY-MM-DD") %> // Date tomorrow <% tp.date.tomorrow() %> // Date tomorrow with format <% tp.date.tomorrow("Do MMMM YYYY") %> // This week's Monday <% tp.date.weekday("YYYY-MM-DD", 0) %> // Next Monday <% tp.date.weekday("YYYY-MM-DD", 7) %> // File's title Monday <% tp.date.weekday("YYYY-MM-DD", 0, tp.file.title, "YYYY-MM-DD") %> // File's title previous Monday <% tp.date.weekday("YYYY-MM-DD", -7, tp.file.title, "YYYY-MM-DD") %> // Date yesterday <% tp.date.yesterday() %> // Date yesterday with format <% tp.date.yesterday("Do MMMM YYYY") %> ``` -------------------------------- ### tp.web.random_picture() usage examples Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/web-module.html Shows how to get a random image from Unsplash. The size parameter uses the format x. The query parameter can include multiple search terms separated by commas. The include_size parameter defaults to false. ```templater // Random picture <% await tp.web.random_picture() %> // Random picture with size <% await tp.web.random_picture("200x200") %> // Random picture with size and query <% await tp.web.random_picture("200x200", "landscape,water") %> ``` -------------------------------- ### Suggester: Basic, Mapping, Files, Tags, Reuse, Default Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/system-module.html Examples of tp.system.suggester for single selection. Includes basic usage, mapping function, file selection, tag selection, reusing the selected value, and setting a default value. ```templater <% await tp.system.suggester(["Happy", "Sad", "Confused"], ["Happy", "Sad", "Confused"]) %> ``` ```templater <% await tp.system.suggester((item) => item, ["Happy", "Sad", "Confused"]) %> ``` ```templater [[<% (await tp.system.suggester((item) => item.basename, tp.app.vault.getMarkdownFiles())).basename %>]] ``` ```templater <% await tp.system.suggester(item => item, Object.keys(tp.app.metadataCache.getTags()).map(x => x.replace("#", ""))) %> ``` ```templater <%* let selectedValue = await tp.system.suggester(["Happy", "Sad", "Confused"], ["Happy", "Sad", "Confused"]); %> # <% selectedValue %> selected value: <% selectedValue %> ``` ```templater <%* let selectedValue = await tp.system.suggester(["Happy", "Sad", "Confused"], ["Happy", "Sad", "Confused"], false, "", undefined, "Confused"); %> # <% selectedValue %> selected value: <% selectedValue %> ``` -------------------------------- ### Templater template example Source: https://silentvoid13.github.io/Templater/introduction.html Shows a template file using Templater syntax with frontmatter, date functions, navigation links, title, and a daily quote. The output demonstrates the rendered result with actual dates and a quote. ```markdown --- creation date: <% tp.file.creation_date() %> modification date: <% tp.file.last_modified_date("dddd Do MMMM YYYY HH:mm:ss") %> --- << [[<% tp.date.now("YYYY-MM-DD", -1) %>]] | [[<% tp.date.now("YYYY-MM-DD", 1) %>]] >> # <% tp.file.title %> <% tp.web.daily_quote() %> ``` ```markdown --- creation date: 2021-01-07 17:20 modification date: Thursday 7th January 2021 17:20:43 --- << [[2021-04-08]] | [[2021-04-10]] >> # Test Test > Do the best you can until you know better. Then when you know better, do better. > — Maya Angelou ``` -------------------------------- ### File creation with tp.file.create_new Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/file-module.html Creates a new file with specified content and name. Options include using a template, opening the created note, and specifying the target folder (current, string path, or TFolder). The last example appends a link to the created file in the current note. ```templater <%* await tp.file.create_new("MyFileContent", "MyFilename") %> ``` ```templater <%* await tp.file.create_new(tp.file.find_tfile("MyTemplate"), "MyFilename") %> ``` ```templater <%* await tp.file.create_new("MyFileContent", "MyFilename", true) %> ``` ```templater <%* await tp.file.create_new("MyFileContent", "MyFilename", false, tp.file.folder(true)) %> ``` ```templater <%* await tp.file.create_new("MyFileContent", "MyFilename", false, "Path/To/MyFolder") %> ``` ```templater <%* await tp.file.create_new("MyFileContent", "MyFilename", false, tp.app.vault.getAbstractFileByPath("MyFolder")) %> ``` ```templater [[<% (await tp.file.create_new("MyFileContent", "MyFilename")).basename %>]] ``` -------------------------------- ### InternalModuleDate class example Source: https://silentvoid13.github.io/Templater/internal-functions/contribute.html Example of an internal module class extending InternalModule, showing how to register static templates for date-related functions. It uses the `name` property and `createStaticTemplates` method to set static templates. ```typescript export class InternalModuleDate extends InternalModule { name = "date"; async createStaticTemplates() { this.static_templates.set("now", this.generate_now()); this.static_templates.set("tomorrow", this.generate_tomorrow()); this.static_templates.set("yesterday", this.generate_yesterday()); } async updateTemplates() {} generate_now() { return (format: string = "YYYY-MM-DD", offset?: number, reference?: string, reference_format?: string) => { if (reference && !window.moment(reference, reference_format).isValid()) { throw new Error("Invalid title date format, try specifying one with the argument 'reference'"); } return get_date_string(format, offset, reference, reference_format); } } generate_tomorrow() { return (format: string = "YYYY-MM-DD") => { return get_date_string(format, 1); } } generate_yesterday() { return (format: string = "YYYY-MM-DD") => { return get_date_string(format, -1); } } } ``` -------------------------------- ### tp.web.request() usage examples Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/web-module.html Shows how to make an HTTP request to a URL and optionally extract data from the response using a path. The path is a JSON path within the response. ```templater // Simple request <% await tp.web.request("https://jsonplaceholder.typicode.com/todos/1") %> // Request with path <% await tp.web.request("https://jsonplaceholder.typicode.com/todos", "0.title") %> ``` -------------------------------- ### tp.file.tags - Get file tags Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/file-module.html Retrieves the file's tags as an array of strings. ```templater // File tags <% tp.file.tags %> ``` -------------------------------- ### Get all folders using tp.app.vault.getAllLoadedFiles() Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/obsidian-module.html Filters all loaded files to return folder names. Uses tp.obsidian.TFolder to identify folders. ```javascript // Get all folders <% tp.app.vault.getAllLoadedFiles() .filter(x => x instanceof tp.obsidian.TFolder) .map(x => x.name) %> ``` -------------------------------- ### Template with internal date functions Source: https://silentvoid13.github.io/Templater/terminology.html Example template containing two commands that call the internal functions tp.date.yesterday and tp.date.tomorrow, each with a format argument. ```plaintext Yesterday: <% tp.date.yesterday("YYYY-MM-DD") %> Tomorrow: <% tp.date.tomorrow("YYYY-MM-DD") %> ``` -------------------------------- ### File rename with tp.file.rename Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/file-module.html Renames the current file. The second example appends '2' to the current title. ```templater <%* await tp.file.rename("MyNewName") %> ``` ```templater <%* await tp.file.rename(tp.file.title + "2") %> ``` -------------------------------- ### Multi-suggester: Basic, Mapping, Files, Tags, Reuse, Default Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/system-module.html Examples of tp.system.multi_suggester for selecting multiple items. Includes basic usage, mapping function, file selection, tag selection, reusing the selected values, and setting a default selection. ```templater <% await tp.system.multi_suggester(["Happy", "Sad", "Confused"], ["Happy", "Sad", "Confused"]) %> ``` ```templater <% await tp.system.multi_suggester((item) => item, ["Happy", "Sad", "Confused"]) %> ``` ```templater <% (await tp.system.multi_suggester((item) => item.basename, tp.app.vault.getMarkdownFiles())).map(f => `[[${f.basename}]]`) %> ``` ```templater <% await tp.system.multi_suggester(item => item, Object.keys(tp.app.metadataCache.getTags()).map(x => x.replace("#", ""))) %> ``` ```templater <%* let selectedValues = await tp.system.multi_suggester(["Happy", "Sad", "Confused"], ["Happy", "Sad", "Confused"]); %> # <% selectedValues %> selected values: <% selectedValues %> ``` ```templater <%* let selectedValue = await tp.system.multi_suggester(["Happy", "Sad", "Confused"], ["Happy", "Sad", "Confused"], false, "", undefined, ["Happy", "Confused"]); %> # <% selectedValue %> selected value: <% selectedValue %> ``` -------------------------------- ### File move with tp.file.move Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/file-module.html Moves the current file to a new path. The first example moves to a folder keeping the title; the second moves and renames. ```templater <%* await tp.file.move("/A/B/" + tp.file.title) %> ``` ```templater <%* await tp.file.move("/A/B/NewTitle") %> ``` -------------------------------- ### File existence with tp.file.exists Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/file-module.html Checks if a file exists at the given path. The second example checks the current file's existence. ```templater <% await tp.file.exists("MyFolder/MyFile.md") %> ``` ```templater <% await tp.file.exists(tp.file.folder(true) + "/" + tp.file.title + ".md") %> ``` -------------------------------- ### Export an object of functions (CommonJS) Source: https://silentvoid13.github.io/Templater/user-functions/script-user-functions.html Create a script that exports an object where each property is a function. This example exports note, tip, and warning functions that format text as callouts. ```javascript function formatAsCallout(text, type = "note") { const blockQuoteLines = text.split("\n").map((line) => `> ${line}`); return `> [!${type}]\n${blockQuoteLines.join("\n")}`; } module.exports = { note: (text) => formatAsCallout(text, "note"), tip: (text) => formatAsCallout(text, "tip"), warning: (text) => formatAsCallout(text, "warning"), }; ``` -------------------------------- ### tp.file.selection - Get text selection Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/file-module.html Retrieves the active file's text selection. ```templater // File selection <% tp.file.selection() %> ``` -------------------------------- ### tp.file.find_tfile - Find TFile instance Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/file-module.html Searches for a file by filename and returns its TFile instance. The example accesses the basename property of the found file. ```templater // File find TFile <% tp.file.find_tfile("MyFile").basename %> ``` -------------------------------- ### Dynamic command with tp.file.last_modified_date Source: https://silentvoid13.github.io/Templater/commands/dynamic-command.html Declare a dynamic command by adding a plus sign after the command opening tag (<%+). This example displays the last modified date and only executes in preview mode. Note that dynamic commands have known issues and may not be maintained; Dataview is suggested as an alternative. ```markdown Last modified date: <%+ tp.file.last_modified_date() %> ``` -------------------------------- ### tp.web.daily_quote() usage examples Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/web-module.html Shows how to retrieve a daily quote as a callout. Without arguments, uses Obsidian's display language, falling back to English. Pass a language code like "es" to select a specific quotes database. ```templater // Daily quote <% await tp.web.daily_quote() %> // Daily quote in Spanish <% await tp.web.daily_quote("es") %> ``` -------------------------------- ### Invoke an object method from a script user function Source: https://silentvoid13.github.io/Templater/user-functions/script-user-functions.html Call a method from an exported object using dot notation. This example calls the note method of my_script with a string containing a newline. ```markdown <% tp.user.my_script.note("Line 1\nLine2") %> ``` -------------------------------- ### tp.file.title - Get file title Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/file-module.html Retrieves the file's title. The example also shows stripping a Zettelkasten ID from the title by splitting on spaces. ```templater // File title <% tp.file.title %> // Strip the Zettelkasten ID of title (if space separated) <% tp.file.title.split(" ")[1] %> ``` -------------------------------- ### Frontmatter with list of categories Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/frontmatter-module.html Example frontmatter block containing a list of categories. This is used with the following JavaScript array manipulation example. ```yaml --- categories: - book - movie --- ``` -------------------------------- ### tp.system.suggester basic usage and mapping function Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/system-module.html Shows basic usage of tp.system.suggester with an array of strings, and an equivalent version using a mapping function. The mapping function returns the item itself, producing the same result. ```javascript // Suggester <% await tp.system.suggester(["Happy", "Sad", "Confused"], ["Happy", "Sad", "Confused"]) %> // Suggester with mapping function (same as above example) <% await tp.system.suggester((item) => item, ["Happy", "Sad", "Confused"]) %> ``` -------------------------------- ### tp.system.suggester(text_items, items, throw_on_cancel, placeholder, limit, default_value) Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/system-module.html Spawns a suggester prompt and returns the user's chosen item. The function accepts an array of display texts or a mapping function, an array of items, and optional parameters for cancellation behavior, placeholder, limit, and default value. ```APIDOC ## tp.system.suggester(text_items, items, throw_on_cancel, placeholder, limit, default_value) ### Description Spawns a suggester prompt and returns the user's chosen item. ### Method Function call ### Signature `tp.system.suggester(text_items: string[] | ((item: T) => string), items: T[], throw_on_cancel: boolean = false, placeholder: string = "", limit?: number = undefined, default_value?: T = undefined)` ### Parameters - **text_items** (string[] | ((item: T) => string)) - Required - Array of strings representing the text that will be displayed for each item in the suggester prompt. This can also be a function that maps an item to its text representation. - **items** (T[]) - Required - Array containing the values of each item in the correct order. - **throw_on_cancel** (boolean) - Optional - Throws an error if the prompt is canceled, instead of returning a `null` value. Defaults to `false`. - **placeholder** (string) - Optional - Placeholder string of the prompt. Defaults to `""`. - **limit** (number) - Optional - Limit the number of items rendered at once (useful to improve performance when displaying large lists). Defaults to `undefined`. - **default_value** (T) - Optional - Default value to initialize the suggester with. Defaults to `undefined`. ### Return Value Returns the user's chosen item from the `items` array, or `null` if canceled and `throw_on_cancel` is `false`. ### Examples ``` // Suggester <% await tp.system.suggester(["Happy", "Sad", "Confused"], ["Happy", "Sad", "Confused"]) %> // Suggester with mapping function (same as above example) <% await tp.system.suggester((item) => item, ["Happy", "Sad", "Confused"]) %> // Suggester for files [[<% (await tp.system.suggester((item) => item.basename, tp.app.vault.getMarkdownFiles())).basename %>]] // Suggester for tags <% await tp.system.suggester(item => item, Object.keys(tp.app.metadataCache.getTags()).map(x => x.replace("#", ""))) %> // Reuse value from suggester <%* let selectedValue = await tp.system.suggester(["Happy", "Sad", "Confused"], ["Happy", "Sad", "Confused"]); %> # <% selectedValue %> selected value: <% selectedValue %> // Default value for the suggester <%* let selectedValue = await tp.system.suggester(["Happy", "Sad", "Confused"], ["Happy", "Sad", "Confused"], false, "", undefined, "Confused"); %> # <% selectedValue %> selected value: <% selectedValue %> ``` ``` -------------------------------- ### tp.system.prompt(prompt_text, default_value, throw_on_cancel, multiline, select_default_value) Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/system-module.html Spawns a prompt modal and returns the user's input. The function accepts optional parameters for prompt text, default value, cancellation behavior, multiline input, and pre-selecting the default value. ```APIDOC ## tp.system.prompt(prompt_text, default_value, throw_on_cancel, multiline, select_default_value) ### Description Spawns a prompt modal and returns the user's input. ### Method Function call ### Endpoint `tp.system.prompt(prompt_text?: string, default_value?: string, throw_on_cancel: boolean = false, multiline?: boolean = false, select_default_value?: boolean = false)` ### Parameters #### Function Parameters - **prompt_text** (string) - Optional - Text placed above the input field. - **default_value** (string) - Optional - A default value for the input field. - **throw_on_cancel** (boolean) - Optional - Throws an error if the prompt is canceled, instead of returning a `null` value. Defaults to `false`. - **multiline** (boolean) - Optional - If set to `true`, the input field will be a multiline textarea. Defaults to `false`. - **select_default_value** (boolean) - Optional - If set to `true`, the default value shown when the modal opens is selected, so typing replaces it. Defaults to `false`. ### Request Example ``` // Prompt <% await tp.system.prompt("Please enter a value") %> // Prompt with default value <% await tp.system.prompt("What is your mood today?", "happy") %> // Multiline prompt <% await tp.system.prompt("What is your mood today?", null, false, true) %> // Prompt with pre-selected default value <% await tp.system.prompt("What is your mood today?", "Input a mood...", false, false, true) %> // Reuse output from prompt <%* let value = await tp.system.prompt("Please enter a value"); %> # <% value %> selected value: <% value %> ``` ### Response #### Success Response Returns the user's input as a string. #### Response Example ``` // Prompt <% await tp.system.prompt("Please enter a value") %> ``` ``` -------------------------------- ### File title with tp.file.title Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/file-module.html Returns the title of the current file. The second example strips a Zettelkasten ID if the title is space-separated. ```templater <% tp.file.title %> ``` ```templater <% tp.file.title.split(" ")[1] %> ``` -------------------------------- ### Invalid invocations of tp.date.now Source: https://silentvoid13.github.io/Templater/syntax.html Examples of invalid invocations that incorrectly include argument names, types, and optional markers in the call. ```plaintext tp.date.now(format: string = "YYYY-MM-DD") ``` ```plaintext tp.date.now(format: string = "YYYY-MM-DD", offset?: 0) ``` -------------------------------- ### tp.system.suggester for files Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/system-module.html Uses a mapping function to display file basenames and returns the selected file's basename wrapped in a wiki link. The suggester is populated with all markdown files in the vault. ```javascript // Suggester for files [[<% (await tp.system.suggester((item) => item.basename, tp.app.vault.getMarkdownFiles())).basename %>]] ``` -------------------------------- ### tp.file.path - Get file path Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/file-module.html Retrieves the file's absolute path on the system. With relative=true, returns the vault-relative path. ```templater // File path <% tp.file.path() %> // File relative path (relative to vault root) <% tp.file.path(true) %> ``` -------------------------------- ### tp.file.create_new(template: TFile | string, filename: string = 'Untitled', open_new: boolean = false, folder?: TFolder | string) Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/file-module.html Creates a new file using a specified template or with a specified content. Supports specifying filename, whether to open the new file, and the target folder. ```APIDOC ## tp.file.create_new(template: TFile | string, filename: string = 'Untitled', open_new: boolean = false, folder?: TFolder | string) ### Description Creates a new file using a specified template or with a specified content. ### Parameters - **template** (TFile | string) - Required - Either the template used for the new file content, or the file content as a string. If it is the template to use, you retrieve it with `tp.file.find_tfile(TEMPLATENAME)`. - **filename** (string) - Optional - The filename of the new file, defaults to ``` -------------------------------- ### File creation date with tp.file.creation_date Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/file-module.html Returns the creation date of the current file. Optionally format it using moment.js format strings. ```templater <% tp.file.creation_date() %> ``` ```templater <% tp.file.creation_date("dddd Do MMMM YYYY HH:mm") %> ``` -------------------------------- ### tp.file.create_new Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/file-module.html Creates a new file with specified content or from a template. Can open the created note and specify the folder. ```APIDOC ## tp.file.create_new ### Description Creates a new file with the given content or from a template. Optionally opens the created note and specifies the folder. ### Usage <%* await tp.file.create_new(content, filename, open, folder) %> ### Parameters - **content** (string or TFile) - Required - The content of the new file, or a TFile object to use as a template. - **filename** (string) - Required - The name of the new file (without extension). - **open** (boolean) - Optional - If true, opens the created note. Default is false. - **folder** (string or TFolder) - Optional - The folder where to create the file. Can be a string path or a TFolder object. If not provided, uses the current folder. ### Examples - Create with content: <%* await tp.file.create_new("MyFileContent", "MyFilename") %> - Create from template: <%* await tp.file.create_new(tp.file.find_tfile("MyTemplate"), "MyFilename") %> - Create and open: <%* await tp.file.create_new("MyFileContent", "MyFilename", true) %> - Create in current folder: <%* await tp.file.create_new("MyFileContent", "MyFilename", false, tp.file.folder(true)) %> - Create in specified folder (string): <%* await tp.file.create_new("MyFileContent", "MyFilename", false, "Path/To/MyFolder") %> - Create in specified folder (TFolder): <%* await tp.file.create_new("MyFileContent", "MyFilename", false, tp.app.vault.getAbstractFileByPath("MyFolder")) %> ### Returns - **TFile** - The created file object. ``` -------------------------------- ### tp.file.rename - Rename file Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/file-module.html Renames the file, keeping the same file extension. The example shows renaming to a fixed name and appending a number to the current title. ```templater // File rename <%* await tp.file.rename("MyNewName") %> // File append a 2 to the file name <%* await tp.file.rename(tp.file.title + "2") %> ``` -------------------------------- ### tp.system.multi_suggester(text_items, items, throw_on_cancel, title, limit, default_values) Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/system-module.html Spawns a suggester prompt that supports selecting multiple items and returns the user's chosen items. The function accepts an array of display strings or a mapping function, an array of item values, and optional parameters for cancellation behavior, title, limit, and default values. ```APIDOC ## tp.system.multi_suggester(text_items, items, throw_on_cancel, title, limit, default_values) ### Description Spawns a suggester prompt that supports selecting multiple items and returns the user's chosen items. ### Method Function call ### Endpoint `tp.system.multi_suggester(text_items: string[] | ((item: T) => string), items: T[], throw_on_cancel: boolean = false, title: string = "", limit?: number = undefined, default_values?: T[] = undefined)` ### Parameters #### Function Parameters - **text_items** (string[] | ((item: T) => string)) - Required - Array of strings representing the text that will be displayed for each item in the suggester prompt. This can also be a function that maps an item to its text representation. - **items** (T[]) - Required - Array containing the values of each item in the correct order. - **throw_on_cancel** (boolean) - Optional - Throws an error if the prompt is canceled, instead of returning a `null` value. Defaults to `false`. - **title** (string) - Optional - Text placed at the top of the modal. Defaults to `""`. - **limit** (number) - Optional - Limit the number of items rendered at once (useful to improve performance when displaying large lists). Defaults to `undefined`. - **default_values** (T[]) - Optional - Default values to initialize the suggester with. Defaults to `undefined`. ### Request Example ``` // Multi-suggester <% await tp.system.multi_suggester(["Happy", "Sad", "Confused"], ["Happy", "Sad", "Confused"]) %> // Multi-suggester with mapping function (same as above example) <% await tp.system.multi_suggester((item) => item, ["Happy", "Sad", "Confused"]) %> // Multi-suggester for files <% (await tp.system.multi_suggester((item) => item.basename, tp.app.vault.getMarkdownFiles())).map(f => `[[${f.basename}]]`) %> // Multi-suggester for tags <% await tp.system.multi_suggester(item => item, Object.keys(tp.app.metadataCache.getTags()).map(x => x.replace("#", ""))) %> // Reuse value from multi-suggester <%* let selectedValues = await tp.system.multi_suggester(["Happy", "Sad", "Confused"], ["Happy", "Sad", "Confused"]); %> # <% selectedValues %> selected values: <% selectedValues %> // Default value for the suggester <%* let selectedValue = await tp.system.multi_suggester(["Happy", "Sad", "Confused"], ["Happy", "Sad", "Confused"], false, "", undefined, ["Happy", "Confused"]); %> # <% selectedValue %> selected value: <% selectedValue %> ``` ### Response #### Success Response Returns the user's chosen items as an array of type T. #### Response Example ``` // Multi-suggester <% await tp.system.multi_suggester(["Happy", "Sad", "Confused"], ["Happy", "Sad", "Confused"]) %> ``` ``` -------------------------------- ### File include with tp.file.include Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/file-module.html Includes the content of another file. Supports wiki links, TFile objects, sections, and blocks. ```templater <% await tp.file.include("[[Template1]]") %> ``` ```templater <% await tp.file.include(tp.file.find_tfile("MyFile")) %> ``` ```templater <% await tp.file.include("[[MyFile#Section1]]") %> ``` ```templater <% await tp.file.include("[[MyFile#^block1]]") %> ``` -------------------------------- ### tp.file.folder - Get folder name Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/file-module.html Retrieves the file's folder name. With absolute=true, returns the vault-absolute path; otherwise returns the basename of the folder. Defaults to false. ```templater // File folder (Folder) <% tp.file.folder() %> // File folder with vault-absolute path (Path/To/Folder) <% tp.file.folder(true) %> ``` -------------------------------- ### tp.file.include(include_link: string | TFile) Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/file-module.html Include the content of another file, resolving templates in the included content. ```APIDOC ## `tp.file.include(include_link: string | TFile)` ### Description Includes the file's link content. Templates in the included content will be resolved. ### Parameters - **include_link** (string | TFile) - Required - The link to the file to include, e.g. `"[[MyFile]]"`, or a TFile object. Also supports sections or blocks inclusions. ### Example ``` <% await tp.file.include("[[Template1]]") %> <% await tp.file.include(tp.file.find_tfile("MyFile")) %> <% await tp.file.include("[[MyFile#Section1]]") %> <% await tp.file.include("[[MyFile#^block1]]") %> ``` ``` -------------------------------- ### tp.file.last_modified_date - Get last modified date Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/file-module.html Retrieves the file's last modification date. Accepts a format string, defaulting to "YYYY-MM-DD HH:mm". ```templater // File last modified date <% tp.file.last_modified_date() %> // File last modified date with format <% tp.file.last_modified_date("dddd Do MMMM YYYY HH:mm") %> ``` -------------------------------- ### Retrieve file content with tp.file.content Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/file-module.html Returns the full content of the current file as a string. ```templater <% tp.file.content %> ``` -------------------------------- ### tp.file.exists - Check file existence Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/file-module.html Checks if a file exists by its full vault-relative path including extension. Returns a boolean. The example shows checking a specific file and the current file. ```templater // File existence <% await tp.file.exists("MyFolder/MyFile.md") %> // File existence of current file <% await tp.file.exists(tp.file.folder(true) + "/" + tp.file.title + ".md") %> ``` -------------------------------- ### File selection with tp.file.selection Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/file-module.html Returns the currently selected text in the editor. ```templater <% tp.file.selection() %> ``` -------------------------------- ### tp.system.suggester for tags Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/system-module.html Displays tags from the metadata cache, stripping the leading '#' character. The selected tag is returned as a string. ```javascript // Suggester for tags <% await tp.system.suggester(item => item, Object.keys(tp.app.metadataCache.getTags()).map(x => x.replace("#", ""))) %> ``` -------------------------------- ### Invoke a script user function with tp.user Source: https://silentvoid13.github.io/Templater/user-functions/script-user-functions.html Call the exported function from a template using the tp.user object. The function name is the script file name. This example calls my_script with a string argument. ```markdown <% tp.user.my_script("Hello World!") %> ``` -------------------------------- ### Clipboard: tp.system.clipboard() Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/system-module.html Retrieves the current clipboard content. Use in a template to insert clipboard text. ```templater <% tp.system.clipboard() %> ``` -------------------------------- ### tp.web.random_picture(size?: string, query?: string, include_size?: boolean) Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/web-module.html Gets a random image from https://unsplash.com/. The size parameter specifies the image dimensions, query limits selection to matching photos, and include_size optionally includes the size in the image link markdown. ```APIDOC ## tp.web.random_picture(size?: string, query?: string, include_size?: boolean) ### Description Gets a random image from `https://unsplash.com/`. ### Parameters - **size** (string) - Optional - Image size in the format `x`. - **query** (string) - Optional - Limits selection to photos matching a search term. Multiple search terms can be passed separated by a comma. - **include_size** (boolean) - Optional - Include the specified size in the image link markdown. Defaults to false. ### Example ``` // Random picture <% await tp.web.random_picture() %> // Random picture with size <% await tp.web.random_picture("200x200") %> // Random picture with size and query <% await tp.web.random_picture("200x200", "landscape,water") %> ``` ``` -------------------------------- ### Documentation syntax for internal functions Source: https://silentvoid13.github.io/Templater/syntax.html Shows the documentation syntax used to describe internal functions, including argument names, types, optional markers, default values, and type unions. This syntax is for documentation only, not for actual invocation. ```plaintext tp.(arg1_name: type, arg2_name?: type, arg3_name: type = , arg4_name: type1|type2, ...) ``` -------------------------------- ### Call a system command user function named 'echo' Source: https://silentvoid13.github.io/Templater/user-functions/overview.html Use the tp.user.echo() syntax to invoke a system command user function. The example shows a complete command invocation within a Templater template. Note that user functions are currently unavailable on Obsidian for mobile. ```plaintext <% tp.user.echo() %> ``` -------------------------------- ### File tags with tp.file.tags Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/file-module.html Returns the tags of the current file. ```templater <% tp.file.tags %> ``` -------------------------------- ### Clipboard retrieval with tp.system.clipboard() Source: https://silentvoid13.github.io/Templater/internal-functions/internal-modules/system-module.html Retrieves the clipboard's content. Use in a Templater template to insert the clipboard text. ```templater // Clipboard <% tp.system.clipboard() %> ```