Read and Paste frontmatter-variable

I want to read the value of a frontmatter variable and insert it at the cursor position.
All I get is the result of a new file being created and the error message in it.
Here is my last attempt of code - any suggestions?

<%*
const kbg = tp.frontmatter["kurzbeleg"];
if (kbg) {
    // Wert von "kurzbeleg" direkt an der Cursorposition einfügen
    tR = kbg;
} else {
    // Fehlermeldung, falls "kurzbeleg" nicht vorhanden ist
    tR = "kurzbeleg-Property nicht gefunden";
}
%>

You could try to replace the tR = ...; by tR += ...; :thinking:

Although, as you’re mentioning that :

… maybe you’re just not using the appropriate Templater command :woman_shrugging:

At least, this seems to work for me when applied on a note using the Templater command: Templater: Open insert template modal :

<%*
const kbg = tp.frontmatter["kurzbeleg"];
if (kbg) {
    // Wert von "kurzbeleg" direkt an der Cursorposition einfügen
    tR += kbg;
} else {
    // Fehlermeldung, falls "kurzbeleg" nicht vorhanden ist
    tR += "kurzbeleg-Property nicht gefunden";
}
%>

How do you insert your template?

Oh wow! Shame on me. This simple code of @Pch works brilliantly if you don’t tell the templater to “Create…” but rather to “Insert…”.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.