Document not found (404)
+This URL is invalid, sorry. Please use the navigation bar or search to continue.
+ +diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 00000000..e69de29b diff --git a/404.html b/404.html new file mode 100644 index 00000000..3ecb66d9 --- /dev/null +++ b/404.html @@ -0,0 +1,167 @@ + + +
+ + +This URL is invalid, sorry. Please use the navigation bar or search to continue.
+ +With this command utility, you can declare a command as "dynamic", which means that this command will be resolved when entering preview mode.
+To declare a dynamic command add a plus +
sign after the command opening tag: <%+
That's it, your command will now be executed only in preview mode.
+This is useful for internal functions like tp.file.last_modified_date
for example:
Last modified date: <%+ tp.file.last_modified_date() %>
+
+Note: Dynamic commands have known issues, and will likely not be maintained going forward (see this issue for more details). In most cases the Dataview plugin is the suggested alternative.
+One "downside" of the preview mode is that it puts the rendered note in cache, to speed things up.
+This means that your dynamic command will be rendered only once, when you open the note, but won't be refreshed after.
+If you want to refresh it, you must close the note to clear the cache and open it again.
+ +This type of command allows us to execute JavaScript code.
+With a JavaScript Execution command, we can pretty much do everything that JavaScript allows us to do. Some examples are given below.
+We can still access the tp
object and all the internal variables / functions from this type of command.
JavaScript Execution commands let you access global namespace variables. This means you can access things like app
or moment
.
Some internal functions are asynchronous. When calling such functions inside a JavaScript execution command, don't forget to use the await
keyword if necessary.
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
.
It is important to note that the tp.system.prompt()
and tp.system.suggester()
both require a await
statement to save the value to a variable
Here are some examples of things you can do using JavaScript Execution Commands:
+<%* 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"); %>
+
+
+ Templater defines 2 types of opening tags, that defines 2 types of commands:
+<%
: Interpolation command. It will output the result of the expression that's inside.<%*
: JavaScript execution command. It will execute the JavaScript code that's inside. It does not output anything by default.The closing tag for a command is always the same: %>
In addition to the different types of commands, you can also use command utilities. They are also declared in the opening tag of the command. All command utilities work with all command types. The available command utilities are:
+ + +By default, commands in Templater are not removing any newlines. Commands are replaced with their values and that's it.
+It can sometimes be useful to have some whitespace control after commands are inserted, which is exactly what this command utility offers.
+Let's have an example. The following template:
+<%* if (tp.file.title == "MyFile" ) { %>
+This is my file!
+<%* } else { %>
+This isn't my file!
+<%* } %>
+Some content ...
+
+Will produce the following output if the condition is false (the same happens when it's true), notice the blank lines:
+
+This isn't my file!
+
+Some content ...
+
+You may want to remove the blank lines produced by the execution commands, that do not produce any output.
+A specific syntax exists for whitespace control:
+_
at the beginning of a tag (<%_
) will trim all whitespace before the command_
at the end of a tag (_%>
) will trim all whitespace after the command-
at the beginning of a tag (<%-
) will trim one newline before the command-
at the end of a tag (-%>
) will trim one newline after the command.In our example, to fix our template to remove the blank lines, we would use the following template (notice the dashes -
at the end of the tags), to remove the blank newlines after the execution commands:
<%* if (tp.file.title == "MyFile" ) { -%>
+This is my file!
+<%* } else { -%>
+This isn't my file!
+<%* } -%>
+Some content ...
+
+Which would produce the following output:
+This isn't my file!
+Some content ...
+
+
+ cmd.exe
and powershell
on Windows are known to have problems with unicode characters.
You can check https://github.com/SilentVoid13/Templater/issues/15#issuecomment-824067020 for a solution.
+Another good solution (probably the best) is to use Windows Terminal and set it as the default shell in Templater's setting.
+Another resource containing solutions that could work for you: https://stackoverflow.com/questions/49476326/displaying-unicode-in-powershell
+ +Templater is a template language that lets you insert variables and functions results into your notes. It will also let you execute JavaScript code manipulating those variables and functions.
+With Templater, you will be able to create powerful templates to automate manual tasks.
+The following template file, that is using Templater syntax:
+---
+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() %>
+
+Will produce the following result when inserted:
+---
+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.
+> — <cite>Maya Angelou</cite>
+
+
+