How to pass arguments to a page template

I’m wondering if there’s a way to create a new page from a template and provide some values to help fill in the template. I currently have multiple page templates set up for organizing lecture notes, but they all end up almost exactly the same aside from a few key things related to the specific course. I’d like to combine them into a single template, but I don’t know how to go about letting the template know which course the notes are for.

I’m aware of the “template(t, args)” function in the expression language, which works fine for live templates but (at least in my testing) not for page templates

placing {{template(my_template, course_name)}} in my page template results in an error: “Function renderTemplate is not available in client”

I’ve attempted to make a space script using the renderTemplate syscall referenced above (template.renderTemplate from syscalls - @silverbulletmd/silverbullet - JSR), but the documentation is pretty minimal and I have not been able to get it working. If anyone could demonstrate the usage of the renderTemplate syscall or suggest a different method of achieving this, I would greatly appreciate it!

It sounds like you want to pass an argument from a limited enumeration (course A, B or C), maybe you can make the choice based on the page name in your template? Note that the page name includes the folder it’s in, so your template could work differently when it’s course A/page and course B/page

1 Like

That’s an interesting idea, but in an ideal world I would also have the template automatically set the name/location of the page based on the argument passed. That might be the best that I can do for now though…