logseq-dynamic-lookup
logseq-dynamic-lookup copied to clipboard
Use any template language inside the template
My case #1: I want to check if a property exists, without using fallbackTemplate.
With a mustache-like template language it can looks like:
{{renderer :lookup, page, :alias:description, "{{#alias}} ({{alias}}){{/alias}}: {{description}}"}}
And specifing list of properties now looks unnecessary:
{{renderer :lookup, page, "{{#alias}} ({{alias}}){{/alias}}: {{description}}"}}
My case #2: Use page name
With a template language we can save a page meta-info as a default context:
{{renderer :lookup, page, "[[{{ page.name }}]] {{#page.props.alias}} ({{page.props.alias}}){{/page.props.alias}}: {{page.props.description}}"}}
I will consider this as "alternative mode", e.g. with a different template identifier -> :lookup_handlebars?
Some thoughts / notes:
- moustache has
{{ }}as delimiters, same as the placeholders in logseq. Need to check if the arguments can be quoted reliably, or escaped otherwise. - currently I retrieve the page properties, nothing else. This needs to be extended, e.g. to support the page metadata retrieval. There might be an ultimately more performant way to do that than the advanced query used now.
- Mustache just an example of idea. May there is another template-language without quoting problems.
- May be you could add a page name to context? It may be taken from renderer params
I'm considering other languages or to create a very basic expression "language" myself.
I'm also considering a way to get and expose the properties in a way that looks natural to Logseq (or maybe it's source code).
Adding the "target" renderer parameter as variable is a good idea either way, could be useful for fallback expressions too.
Either way, I should find some time to work on this before the end of this year.
Sounds very interesting 🔥
Hi, @peanball !
Since that time I've created 🏛 Full House Templates plugin which completely covers my request.
Take a look — you may like it ❤️