### Basic Templater Syntax Example Source: https://github.com/silentvoid13/templater/blob/master/docs/src/introduction.md This template demonstrates inserting file metadata, dates, and external content using Templater's syntax. It requires no specific setup beyond installing the Templater plugin. ```javascript --- 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() %> ``` -------------------------------- ### File Module Function Examples Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/file-module.md Examples demonstrating the usage of various functions within the File Module. These examples are generated dynamically based on the function definitions. ```javascript // description console.log(tp.file.description()) ``` ```javascript // title console.log(tp.file.title()) ``` ```javascript // folder console.log(tp.file.folder()) ``` ```javascript // path console.log(tp.file.path()) ``` ```javascript // extension console.log(tp.file.extension()) ``` ```javascript // aliases console.log(tp.file.aliases()) ``` ```javascript // tags console.log(tp.file.tags()) ``` ```javascript // tasks console.log(tp.file.tasks()) ``` ```javascript // frontmatter console.log(tp.file.frontmatter()) ``` ```javascript // link console.log(tp.file.link()) ``` ```javascript // exists console.log(tp.file.exists("some/path")) ``` ```javascript // add_to_file console.log(tp.file.add_to_file("some/path", "content")) ``` ```javascript // move console.log(tp.file.move("new/path")) ``` ```javascript // delete console.log(tp.file.delete()) ``` -------------------------------- ### Web Module Function Examples Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/web-module.md Examples demonstrating the usage of various functions within the Web Module. These examples are grouped together for comprehensive reference. ```javascript // get await templater.web.get("https://example.com"); // post await templater.web.post("https://example.com", { "key": "value" }); // put await templater.web.put("https://example.com", { "key": "value" }); // delete await templater.web.delete("https://example.com"); // patch await templater.web.patch("https://example.com", { "key": "value" }); // head await templater.web.head("https://example.com"); // options await templater.web.options("https://example.com"); // upload await templater.web.upload("https://example.com", "./file.txt"); // download await templater.web.download("https://example.com", "./file.txt"); // json await templater.web.json("https://example.com"); // text await templater.web.text("https://example.com"); // html await templater.web.html("https://example.com"); // xml await templater.web.xml("https://example.com"); // blob await templater.web.blob("https://example.com"); // stream await templater.web.stream("https://example.com"); // formData await templater.web.formData("https://example.com", { "key": "value" }); // formUrlEncoded await templater.web.formUrlEncoded("https://example.com", { "key": "value" }); // bearer await templater.web.bearer("https://example.com", "token"); // basicAuth await templater.web.basicAuth("https://example.com", "user", "password"); // digestAuth await templater.web.digestAuth("https://example.com", "user", "password"); // oauth1 await templater.web.oauth1("https://example.com", "token", "secret"); // oauth2 await templater.web.oauth2("https://example.com", "token"); // graphql await templater.web.graphql("https://example.com", { "query": "{ hello }" }); // websocket const ws = await templater.web.websocket("wss://example.com"); ws.onmessage = (event) => { console.log(event.data); }; ws.send("Hello WebSocket"); ``` -------------------------------- ### Start Development Server Source: https://github.com/silentvoid13/templater/blob/master/CONTRIBUTING.md Start the development server in watch mode. This command automatically copies build output for live testing in Obsidian. ```sh pnpm dev ``` -------------------------------- ### Install Dependencies Source: https://github.com/silentvoid13/templater/blob/master/CONTRIBUTING.md Install project dependencies using pnpm. This is required after cloning the repository. ```sh pnpm install ``` -------------------------------- ### Templater Example: Date Formatting Source: https://github.com/silentvoid13/templater/blob/master/docs/src/terminology.md Demonstrates using internal functions to get yesterday's and tomorrow's dates in a specific format within a template. ```templater Yesterday: <% tp.date.yesterday("YYYY-MM-DD") %> Tomorrow: <% tp.date.tomorrow("YYYY-MM-DD") %> ``` -------------------------------- ### Install pnpm Source: https://github.com/silentvoid13/templater/blob/master/CONTRIBUTING.md Install the pnpm package manager globally. This is a prerequisite for development. ```sh npm install -g pnpm ``` -------------------------------- ### tp.date.now Function Documentation Example Source: https://github.com/silentvoid13/templater/blob/master/docs/src/syntax.md Illustrates the documentation syntax for the tp.date.now function, showing optional arguments and their types. ```javascript tp.date.now(format?: string = "YYYY-MM-DD", offset?: number|string, reference?: string, reference_format?: string) ``` -------------------------------- ### All Date Function Examples Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/date-module.md A consolidated list of examples for various date functions available in Templater, including formatting, differences, and date arithmetic. ```javascript // Get current date in YYYY-MM-DD format ``` ```javascript // Get current date in YYYY-MM-DD HH:mm format ``` ```javascript // Get current date in YYYY-MM-DD HH:mm:ss format ``` ```javascript // Get current date in YYYY-MM-DD HH:mm:ss.SSS format ``` ```javascript // Get current date in YYYY-MM-DDTHH:mm:ss.SSSZ format ``` ```javascript // Get current date in YYYY-MM-DDTHH:mm:ss.SSS+HH:mm format ``` ```javascript // Get current date in a custom format ``` ```javascript // Get current date in a custom format with locale ``` ```javascript // Format a specific date ``` ```javascript // Get the difference in days between two dates ``` ```javascript // Add 5 days to the current date ``` ```javascript // Subtract 3 days from the current date ``` -------------------------------- ### Templater System Module All Examples Aggregation Template Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/system-module.md Shows the Nunjucks template used to iterate through all system functions and display their respective examples. ```javascript {%- for key, fn in tp.system.functions %} {% for example in fn.examples -%} // {{ example.name}} {{ example.example }} {% endfor -%} {%- endfor %} ``` -------------------------------- ### Templater Function Example Rendering Template Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/system-module.md Illustrates the Nunjucks template structure used to render individual examples for a specific Templater system function. ```javascript {% for example in fn.examples -%} // {{ example.name}} {{ example.example }} {% endfor -%} ``` -------------------------------- ### Get All Configuration Values Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/config-module.md Retrieves all currently loaded configuration settings as an object. This can be helpful for debugging or inspection. ```javascript tp.config.all() ``` -------------------------------- ### Get Configuration Description Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/config-module.md Retrieves the description of the config module itself. This is typically used for documentation generation. ```javascript tp.config.description ``` -------------------------------- ### Define and Call a System Command User Function Source: https://github.com/silentvoid13/templater/blob/master/docs/src/user-functions/system-user-functions.md This example shows how to define a system command user function and then call it with arguments. The arguments are passed as a JavaScript object and become available as environment variables in the executed system command. ```javascript <% tp.user.echo({a: "value 1", b: "value 2"}) %> ``` -------------------------------- ### Get Configuration Value Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/config-module.md Retrieves a configuration value using its key. Ensure the configuration is loaded before accessing values. ```javascript tp.config.get("key") ``` -------------------------------- ### Basic Templater Template Example Source: https://github.com/silentvoid13/templater/blob/master/docs/src/commands/whitespace-control.md This template demonstrates the default behavior of Templater commands, which do not remove newlines, potentially leading to blank lines in the output. ```html <%* if (tp.file.title == "MyFile" ) { %> This is my file! <%* } else { %> This isn't my file! <%* } %> Some content ... ``` -------------------------------- ### Using Internal Functions in System Commands Source: https://github.com/silentvoid13/templater/blob/master/docs/src/user-functions/system-user-functions.md This example demonstrates how internal Templater functions can be used within a system command. The internal function `tp.file.path()` is called and its output is substituted into the system command before execution. ```javascript cat <% tp.file.path() %> ``` -------------------------------- ### Conventional Commits Example Source: https://github.com/silentvoid13/templater/blob/master/CONTRIBUTING.md Follow the Conventional Commits format for commit messages to drive automated changelogs and semantic versioning. ```sh type(scope): description ``` -------------------------------- ### Valid tp.date.now Function Invocations Source: https://github.com/silentvoid13/templater/blob/master/docs/src/syntax.md Examples of correctly calling the tp.date.now function with different argument combinations. ```javascript <% tp.date.now() %> ``` ```javascript <% tp.date.now("YYYY-MM-DD", 7) %> ``` ```javascript <% tp.date.now("YYYY-MM-DD", 7, "2021-04-09", "YYYY-MM-DD") %> ``` ```javascript <% tp.date.now("dddd, MMMM Do YYYY", 0, tp.file.title, "YYYY-MM-DD") %> ``` -------------------------------- ### Use Dynamic Command for Last Modified Date Source: https://github.com/silentvoid13/templater/blob/master/docs/src/commands/dynamic-command.md This example demonstrates using a dynamic command to display the last modified date of a file. Dynamic commands are useful for internal functions that should only run in preview mode. ```javascript Last modified date: <%+ tp.file.last_modified_date() %> ``` -------------------------------- ### Get All Folders Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/app-module.md Retrieves the names of all loaded folders within the Obsidian vault. This is useful for scripting tasks that require knowledge of the vault's directory structure. ```javascript // Get all folders <% tp.app.vault.getAllLoadedFiles() .filter(x => x instanceof tp.obsidian.TFolder) .map(x => x.name) %> ``` -------------------------------- ### Conditional Output based on File Title Source: https://github.com/silentvoid13/templater/blob/master/docs/src/commands/execution-command.md Use JavaScript to conditionally output text based on the file's title. This snippet demonstrates checking if the title starts with 'Hello'. ```javascript <%* if (tp.file.title.startsWith("Hello")) { %> This is a hello file ! <%* } else { %> This is a normal file ! <%* } %> ``` -------------------------------- ### Get Date Difference with tp.date.diff() Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/date-module.md Illustrates calculating the difference between two dates in days using `tp.date.diff()`. Ensure dates are in YYYY-MM-DD format. ```javascript // Get the difference in days between two dates ``` -------------------------------- ### Modify File Content Source: https://github.com/silentvoid13/templater/blob/master/docs/src/commands/execution-command.md Append modified file content to the output string `tR`. This example replaces occurrences of 'stuff' with 'things' in the current file's content. ```javascript <%* tR += tp.file.content.replace(/stuff/, "things"); %> ``` -------------------------------- ### Serve Documentation Locally Source: https://github.com/silentvoid13/templater/blob/master/CONTRIBUTING.md Preview documentation changes locally by serving the mdBook documentation. This command should be run from the 'docs' directory. ```sh cd docs mdbook serve ``` -------------------------------- ### Load Configuration from File Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/config-module.md Loads configuration settings from a specified file path. The file format is typically JSON or YAML. Ensure the file exists and is accessible. ```javascript tp.config.load("path/to/config.json") ``` -------------------------------- ### tp.system.description Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/system-module.md Retrieves a description of the System Module. ```APIDOC ## tp.system.description ### Description Retrieves a description of the System Module. ### Method `tp.system.description()` ### Endpoint N/A (Function call) ### Response - **description** (string) - The description of the System Module. ``` -------------------------------- ### Format Date with tp.date.now() Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/date-module.md Demonstrates formatting the current date using various format strings with the `tp.date.now()` function. ```javascript // Get current date in YYYY-MM-DD format ``` ```javascript // Get current date in YYYY-MM-DD HH:mm format ``` ```javascript // Get current date in YYYY-MM-DD HH:mm:ss format ``` ```javascript // Get current date in YYYY-MM-DD HH:mm:ss.SSS format ``` ```javascript // Get current date in YYYY-MM-DDTHH:mm:ss.SSSZ format ``` ```javascript // Get current date in YYYY-MM-DDTHH:mm:ss.SSS+HH:mm format ``` ```javascript // Get current date in a custom format ``` ```javascript // Get current date in a custom format with locale ``` -------------------------------- ### Define and Use a Helper Function Source: https://github.com/silentvoid13/templater/blob/master/docs/src/commands/execution-command.md Define a JavaScript helper function within the command and then use it to perform an action, such as logging to the console. ```javascript <%* function log(msg) { console.log(msg); } %> ``` ```javascript <%* log("Title: " + tp.file.title) %> ``` -------------------------------- ### Format Specific Date with tp.date.now() Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/date-module.md Shows how to format a specific date string using `tp.date.now()` by providing a date string as the first argument. ```javascript // Format a specific date ``` -------------------------------- ### Basic Command Syntax Source: https://github.com/silentvoid13/templater/blob/master/docs/src/syntax.md A basic Templater command must include both an opening '<%' and closing '%>' tag. ```plaintext <% tp.date.now() %> ``` -------------------------------- ### Function Documentation Syntax Source: https://github.com/silentvoid13/templater/blob/master/docs/src/syntax.md This syntax is for documentation purposes to understand expected arguments, types, and defaults. Do not use this syntax when calling functions. ```javascript tp.(arg1_name: type, arg2_name?: type, arg3_name: type = , arg4_name: type1|type2, ...) ``` -------------------------------- ### tp.config.functions Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/config-module.md Lists and describes the functions available in the config module. ```APIDOC ## tp.config.functions ### Description Lists and describes the functions available in the config module. ### Method N/A ### Endpoint N/A ``` -------------------------------- ### tp.config.description Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/config-module.md Provides a description of the config module. ```APIDOC ## tp.config.description ### Description Provides a description of the config module. ### Method N/A ### Endpoint N/A ``` -------------------------------- ### Reload Configuration Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/config-module.md Reloads the configuration from its source. This is useful after external configuration changes. ```javascript tp.config.reload() ``` -------------------------------- ### Run End-to-End Tests Source: https://github.com/silentvoid13/templater/blob/master/CONTRIBUTING.md Execute end-to-end tests using WebdriverIO against a real Obsidian instance. New features and bug fixes must include corresponding tests. ```sh pnpm test ``` -------------------------------- ### Has Configuration Key Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/config-module.md Checks if a configuration key exists. Returns a boolean value. ```javascript tp.config.has("key") ``` -------------------------------- ### Add Days to Date with tp.date.now() Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/date-module.md Demonstrates adding a specified number of days to the current date using `tp.date.now()` with the `plus` argument. ```javascript // Add 5 days to the current date ``` -------------------------------- ### Declare a Dynamic Command Source: https://github.com/silentvoid13/templater/blob/master/docs/src/commands/dynamic-command.md To declare a dynamic command, add a plus (+) sign after the command opening tag. This ensures the command executes only in preview mode. ```html <%+ %> ``` -------------------------------- ### tp.system.functions Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/system-module.md Provides access to the functions within the System Module. ```APIDOC ## tp.system.functions ### Description Provides access to the functions within the System Module. This is a collection of functions that can be iterated over. ### Method `tp.system.functions` ### Endpoint N/A (Object access) ### Response - **functions** (object) - An object where keys are function names and values are function details (definition, description, args, examples). ``` -------------------------------- ### Set Configuration Value Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/config-module.md Sets a configuration value for a given key. This function is useful for dynamic configuration updates. ```javascript tp.config.set("key", "value") ``` -------------------------------- ### Function Invocation with Arguments Source: https://github.com/silentvoid13/templater/blob/master/docs/src/syntax.md Functions can accept arguments placed between the parentheses. All arguments must be passed in the correct order. ```javascript tp.date.now(arg1_value, arg2_value, arg3_value, ...) ``` -------------------------------- ### User Script with TSDoc Documentation Source: https://github.com/silentvoid13/templater/blob/master/docs/src/user-functions/script-user-functions.md Document your user script functions using TSDoc comments at the top of the file. This provides an intellisense-like experience within Templater. ```javascript /** * This does something cool */ function doSomething() { console.log('Something was done') } module.exports = doSomething; ``` -------------------------------- ### Subtract Days from Date with tp.date.now() Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/date-module.md Shows how to subtract a specified number of days from the current date using `tp.date.now()` with the `minus` argument. ```javascript // Subtract 3 days from the current date ``` -------------------------------- ### Lint and Typecheck Code Source: https://github.com/silentvoid13/templater/blob/master/CONTRIBUTING.md Run linting and TypeScript type checking to ensure code quality and style compliance. This should be run before submitting changes. ```sh pnpm lint ``` -------------------------------- ### Perform HTTP Request Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/obsidian-module.md Makes an HTTP request to a specified URL and processes the response. This allows templates to fetch data from external APIs or web services. The response object contains `json`, `text`, and `headers` properties. ```javascript // HTTP request <%* const response = await tp.obsidian.requestUrl("https://jsonplaceholder.typicode.com/todos/1"); tR += response.json.title; %> ``` -------------------------------- ### Invoke System Command User Function Source: https://github.com/silentvoid13/templater/blob/master/docs/src/user-functions/overview.md Call a system command user function named 'echo' using the standard Templater syntax. Ensure the function is defined elsewhere. ```javascript <% tp.user.echo() %> ``` -------------------------------- ### Format Date with Moment.js Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/date-module.md Utilizes the Moment.js library within Templater to format dates. This provides extensive formatting options beyond the built-in `tp.date.now()`. ```javascript // Format current date using Moment.js ``` ```javascript // Format current date with a specific format string ``` ```javascript // Format current date with locale ``` ```javascript // Add 1 week to the current date ``` ```javascript // Subtract 2 months from the current date ``` ```javascript // Get the difference in hours between two dates ``` ```javascript // Check if a date is before another date ``` ```javascript // Check if a date is after another date ``` ```javascript // Check if a date is the same as another date ``` ```javascript // Get the Unix timestamp of the current date ``` ```javascript // Create a date from a Unix timestamp ``` ```javascript // Get the day of the week (0-6) ``` ```javascript // Get the month (0-11) ``` ```javascript // Get the year ``` ```javascript // Get the current time in HH:mm:ss format ``` -------------------------------- ### Templater Template with Whitespace Control Source: https://github.com/silentvoid13/templater/blob/master/docs/src/commands/whitespace-control.md This template utilizes dashes (-) at the end of execution command tags to trim single newlines after the commands, effectively removing blank lines from the output. ```html <%* if (tp.file.title == "MyFile" ) { -%> This is my file! <%* } else { -%> This isn't my file! <%* } -%> Some content ... ``` -------------------------------- ### Export an Object of Functions Source: https://github.com/silentvoid13/templater/blob/master/docs/src/user-functions/script-user-functions.md Define a JavaScript file that exports an object where each property is a function. This allows you to create multiple related user functions from a single script. ```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"), }; ``` -------------------------------- ### Overwrite tR to Control Output Source: https://github.com/silentvoid13/templater/blob/master/docs/src/commands/execution-command.md Demonstrates how to completely overwrite the `tR` variable to control the final output. This is useful for ignoring previously generated content or setting specific frontmatter. ```javascript <%* tR = "" -%> ``` -------------------------------- ### Formatting List Frontmatter Variables Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/frontmatter-module.md For frontmatter variables that are lists, you can use JavaScript array methods such as `map` and `join` to format their display within your template. ```html <% tp.frontmatter.categories.map(prop => ` - "${prop}"`).join("\n") %> ``` -------------------------------- ### Update Frontmatter of Existing File Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/app-module.md Updates the frontmatter of a specified file by adding or modifying a key-value pair. Ensure the file path is correct and the file exists in the vault. This operation is asynchronous. ```javascript // Update frontmatter of existing file <%* const file = tp.file.find_tfile("path/to/file"); await tp.app.fileManager.processFrontMatter(file, (frontmatter) => { frontmatter["key"] = "value"; }); %> ``` -------------------------------- ### Conditional Output based on Frontmatter Type Source: https://github.com/silentvoid13/templater/blob/master/docs/src/commands/execution-command.md Conditionally output text based on the 'type' property in the file's frontmatter. This snippet checks if the type is 'seedling'. ```javascript <%* if (tp.frontmatter.type === "seedling") { %> This is a seedling file ! <%* } else { %> This is a normal file ! <%* } %> ``` -------------------------------- ### Execute JavaScript After All Templates Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/hooks-module.md Use `tp.hooks.on_all_templates_executed` to run custom JavaScript after all Templater templates have finished executing. This is useful for post-processing tasks like updating file frontmatter or triggering commands from other plugins. ```javascript // Update frontmatter after template finishes executing <%* tp.hooks.on_all_templates_executed(async () => { const file = tp.file.find_tfile(tp.file.path(true)); await tp.app.fileManager.processFrontMatter(file, (frontmatter) => { frontmatter["key"] = "value"; }); }); %> ``` ```javascript // Run a command from another plugin that modifies the current file, after Templater has updated the file <%* tp.hooks.on_all_templates_executed(() => { tp.app.commands.executeCommandById("obsidian-linter:lint-file"); }); -%> ``` -------------------------------- ### Call a Single Function Script Source: https://github.com/silentvoid13/templater/blob/master/docs/src/user-functions/script-user-functions.md Invoke a user function defined by a script that exports a single function. Pass any required arguments to the function. ```javascript <% tp.user.my_script("Hello World!") %> ``` -------------------------------- ### Export a Single Function Source: https://github.com/silentvoid13/templater/blob/master/docs/src/user-functions/script-user-functions.md Define a JavaScript file that exports a single function. This function will be available as a user function in Templater, named after the script file. ```javascript module.exports = function (msg) { return `Message from my script: ${msg}`; }; ``` -------------------------------- ### Call a Specific Function from an Object Export Source: https://github.com/silentvoid13/templater/blob/master/docs/src/user-functions/script-user-functions.md Invoke a specific function exported from a script that exports an object of functions. Access the function using dot notation. ```javascript <% tp.user.my_script.note("Line 1\nLine2") %> ``` -------------------------------- ### Registering Internal Variable/Function Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/contribute.md Use this syntax to register your generated internal variable or function in either the static or dynamic templates map. Ensure the registration is alphabetically ordered. ```typescript this.static_templates.set(, this.generate_()); OR this.dynamic_templates.set(, this.generate_()); ``` -------------------------------- ### Conditional Output based on File Tags Source: https://github.com/silentvoid13/templater/blob/master/docs/src/commands/execution-command.md Conditionally output text based on whether the file includes a specific tag. This snippet checks for the '#todo' tag. ```javascript <%* if (tp.file.tags.contains("#todo")) { %> This is a todo file ! <%* } else { %> This is a finished file ! <%* } %> ``` -------------------------------- ### Accessing Frontmatter Variables Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/frontmatter-module.md Use `tp.frontmatter.` to retrieve a frontmatter variable. For variable names with spaces, use bracket notation like `tp.frontmatter["variable name with spaces"]`. ```html <% tp.frontmatter.alias %> <% tp.frontmatter["note type"] %> ``` -------------------------------- ### Unset Configuration Value Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/config-module.md Removes a configuration value associated with a specific key. Use with caution as it permanently removes the setting. ```javascript tp.config.unset("key") ``` -------------------------------- ### Normalize File Path Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/obsidian-module.md Normalizes a given file path string to ensure it is in a consistent format, which is crucial for reliable file operations across different operating systems or Obsidian versions. ```javascript // Normalize path <% tp.obsidian.normalizePath("Path/to/file.md") %> ``` -------------------------------- ### Convert HTML to Markdown Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/internal-modules/obsidian-module.md Converts an HTML string into its Markdown equivalent. This is helpful when importing content from external sources that use HTML formatting. ```javascript // Html to markdown <% tp.obsidian.htmlToMarkdown("

Heading

Paragraph

") %> ``` -------------------------------- ### Define Internal Date Functions in Templater Source: https://github.com/silentvoid13/templater/blob/master/docs/src/internal-functions/contribute.md This TypeScript class defines static internal templates for date-related functions like 'now', 'tomorrow', and 'yesterday'. It extends the `InternalModule` class and registers these functions in `createStaticTemplates`. ```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); } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.