Help with templater, buttons and generated folder structures

Hi everyone, I’m wondering if people can help me with how to get around a current problem I’m having with a project.

I’m currently working on a vault for my TTRPG campaigns, and I’m trying to generate the folder structure as I go. In a quasi-self-made worldanvil that I keep locally and doesn’t cost me a subscription :sweat_smile:


The idea

To describe how it currently works. I have an initial frontpage with a games list populated dataview, benath this has a ‘new game’ button powered by the button plugin.

This prompts the user to enter a name, and that is then used in a js script to initiate everything for that game using the obsidian API and Templater. Creating a unique folder structure for that game and a front page for that specific game (The Game page)

From there I plan to have dataview and other buttons to add and categorise stuff for each specific game, and easily manage the organisation of everything. Using templates to quickly be able to add all I need with associated metadata.

To summarise an example of adding a new game & a new character

  1. Open to front page
  2. Click ‘new game’ button
  3. Enter game name
  4. Script generates folder structure & game page
  5. click ‘new player’ button.
  6. A new Character note made via template is added to the ‘Characters’ folder

The issue

Templater eat’s my template button!

The main issue I have so far is the button plugin when added on a template.

my button code looks like this:

name New game
type template
action <%_ * tp.user.<Specificscripthere> _%>
templater true

The issue is, if this button is loaded in via a template (for example the game page template being invoked from the main page) templater interprets the code In the code block and resolves it as part of the template.

Depending on how I’ve attempted to get around this so far, it either A: invokes the button code on page creation (so making a game that has an add player button on its front page immediately makes it start trying to add a player afterwards) or simply errors the button into non-existence. So far I’ve found no way to ‘escape’ a template command so it doesn’t get processed.

Getting the file path

Now I’ve looked into other ways of generating the button away from templater, to allow templater to simply focus on filling out the page. The main issue I’ve run into here is simply getting the folder path for the new note and generating it with a template via code. As this path is generated dynamically I cannot ‘prefil’ the information in with a folder template or Quickadds commands.

With templater I simply planned to call it and pass it through to the script as a variable. Just as I have with the initial button. However without that option I’ve been grounded.

I’ve looked into quickadd, but I cannot figure out via the documentation how to pass a preset variable (like the file path) to a macro, only via {{VALUE}} which means I’m typing in redundant information and may as well just click “New note” myself.

I’ve also attempted trying to get around the issue to somehow invoke a templater script via Quickadd. But so far no luck.


Thanks for reading

I hope I’ve provided enough information for someone to show me a miracle here or some obvious method I’ve not seen right before my eyes. Thank for for reading all this and I hope you can help me figure this out so I stop pulling my hair out!

If you need any more information let me know and I’ll reply with it!

Hey, is this the sort of behaviour you’re after? I have a few buttons which don’t have any code in themselves, but they call a template which creates a file from another template

For example, I have a “new note” button, that leads to a template with the following code:

<%*
const fileName = await tp.system.prompt("File name")
const templateName = await tp.system.suggester(["task-tpl","project-tpl"], ["task-tpl","project-tpl"])
tp.file.create_new(tp.file.find_tfile(templateName), fileName, "📥 INBOX") 
%>

This has a pop-up to enter a name for the file, or game name, and that in turn creates a new file from the template I want. This way, your suggester/prompt what have you is in the leapfrog template, and allows you to pass the variable in that sense.

So with reference to the diagram I made, I guess it would be a slightly different approach and look more like the following:

I could be way off the mark here!

1 Like

On re-reading this I suddenly realised I misunderstood something key. This works wonderfully and thank you so much!

1 Like

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