Skip to content

Is there a way to share variables between template blocks? #232

Answered by SilentVoid13
jonasmerlin asked this question in Help
Discussion options

You must be logged in to vote

Hey @jonasmerlin, if the template blocks are in the same template file, then you can re-use the deck variable in another block.

If you look at the doc (https://silentvoid13.github.io/Templater/docs/commands/execution-command), you can do things like that:

<%*
function log(msg) {
    console.log(msg);
}
%>
<%* log("Title: " + tp.file.title) %>

i.e. define a function in a block and use it in another. This works for variables as well of course.

Since you want to output something using an execution command (<%*) you have to use the tR variable as specified in the documentation.
In your use case, this would give something like that:

<%*
    const decks = await app.vault.getAbstractFileByPath("…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jonasmerlin
Comment options

Answer selected by SilentVoid13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants