Templater - How to select and include template from tp.system.suggester?

Hello

I am trying to get template name/link from tp.system.suggester and then use it in tp.file.include.

I have tried various combinations of:

  • tp.system.suggester
  • tp.file.include
  • tR += include_file

The included example files gives an exception:

Uncaught (in promise) TemplaterError: Invalid file format, provide an obsidian link between quotes.
    at InternalModuleFile.eval (plugin:templater-obsidian:2619:17)
    at Generator.next (<anonymous>)
    at eval (plugin:templater-obsidian:63:61)
    at new Promise (<anonymous>)
    at __async (plugin:templater-obsidian:47:10)
    at Object.eval [as include] (plugin:templater-obsidian:2605:30)
    at eval (eval at compile (plugin:templater-obsidian:1:1), <anonymous>:11:9)

Example files

BaseTemplate.md

<%*
const include_file = await tp.system.suggester(
	["Template1", "Template2"],
	["[[Template1]]", "[[Template2]]"],
	false,  "Select Template")

tp.file.include("tR += include_file")
%>

Template1.md

Template1

Template2.md

Template2

Figured it out while doing some other stuff.

It seems that multi line code blocks <%* behave a bit differently compared to single line <%

Splitting it up in two with include separately works:

<%*
...
%>
<% tp.file.include(include_file) %>

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