Is this possible to render a widget in a template? For example a command button next to each task rendered from the query?
I’m not sure, if I got your question right.
- are you refering to page Templates?
- or templates to be used in rendering query results?
What do you want to have the “result” of the rendering as text on your new page?
Maybe you could describe in more detail?
If you want to insert a widget on a new page using a template, you can use this syntax:
${"$"}{widgets.marquee("Hello")}
within the template file.
I’m refering to templates used in queries. I made a test snippet:
mytemplates = mytemplates or {}
mytemplates.test = template.new([==[
* ${name} ${"$"}{widgets.commandButton("Hello", "hello")}
]==])
Then when using this template directly ${mytemplates.test({name = "qwerty"})} it renders
Although printing the same to console
print("Test: " .. mytemplates.test({name = "qwerty"}))
gives me
[Client] [Lua] Test: * qwerty ${widgets.commandButton("Hello", "hello")}
and pasting this content to the page content renders correctly with the button.
Am I doing something wrong or this isn’t currently possible?
You cannot put widgets inside templates, that doesn’t work. This is a restriction that is quite hard to fix, so we’ll have to live with that for a while.
However, you can use widgets inside other widgets, and this is how I often work around this restriction. For instance, in the implementation of the current Library Manager I dynamically build up a HTML table and put widgets in that. Have a look here inside some of the *Widget code, this should give you an idea of how to do this: Library
Note, you cannot put HTML widgets inside templates. Markdown widgets or plain text widgets work fine.
Maybe we should just check for that here and not try to insert the lua table.
