Is there a way to get mediawiki-like templates in Obsidian, where I define variables / parameters that can be inserted in a page, and transclude (embed) the and define those variables?

I looked at the post made last week asking something similar, and was told to use Templater’s dynamic commands. But that only works when switching to reading mode. I want it shown in live preview mode, and if I want to edit it, I could put my caret where it is, like a dataview query.

If you look at the Mediawiki templates documentation, you could make a page named “Thank you” like this with the parameters 1 and 2:

'''A little thank you...'''
for {{{1}}}.
hugs, {{{2}}}

And as shown under Numbered Parameters, on another page, you could embed the page, and define what is shown in place of paramters 1 and 2:

{{Thankyou|1=Me|2=being who you are}}

It then shows up as this:

'''A little thank you...'''
for being who you are.
hugs, me

I’m thinking that maybe dv.view() would be a good fit for you in this case.

It’ll allow you to do something like:

`$= await dv.view("_js/thankyou", { who: "Me", greet: "being who you are" }) `

And with a corresponding file _js/thankyou.js:

const { who, greet } = input

dv.paragraph(`
'''A  little thank you'''
for ${ greet }.
hugs, ${ who }
`)

It’ll produce output like:
image

To some extent can this variant of a template include other markdown, but there are limitations related to the output from any given Dataview query. Some can be countered by proper styling and definition of the elements from your script, and some are harder to work around.

So this should address some of your wants and requests, related to showing in both live-preview and reading, and defining variables to be inserted into that template. How advanced/complex you want to make it, and how much styling you’ll want to use is up to you, but the basic examples just shows the gist of what’s possible to do using dv.view(). You can do some heavy stuff using this method…

1 Like

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