Templates with variables

Things I have tried

I tried to search but could not find the answer. I am also a new user so am learning new things.

What I’m trying to do

I’d like to put my cover letter and alike in Obsidian with multiple magic variables. In other words, I’d like to have a cover letter like such:

Dear {{first_name}},

I’d like to join {{company}} for {{position}}. This {{position}} is very important to me. Blah blah.

Is it possible for Obsidian to give me a pop up to fill in these variables or a place where I can define the variables and they are replaced everywhere in the note, i.e. I type {{position}} once in a pop up and it fills it everywhere in the same note where {{position}} is called?

1 Like

You can use Templater plugin. Here are examples from the documentation:

Mood today: <% tp.system.suggester(["Happy", "Sad", "Confused"], ["Happy", "Sad", "Confused"]) %>

or…

Entered value: <% tp.system.prompt("Please enter a value") %>

You can get pretty creative with this powerful functionality. Good luck!

3 Likes

Thank you! This is super helpful! I’m reading through the documents now and it doesn’t look like I can set variables. Is that correct? i.e. to quote your example, how do I set a variable mood_today so every where it is called, it will use the response I gave it when it prompted me?

OK so I made progress by playing with it and have one last question. My IF statement isn’t working as intended. If I do first_name, it doesn’t work. Any advice on what I could be doing wrong here?


<%*
 let positionName = await tp.system.prompt("Position Title")
 let dateValue = tp.date.now()
 let hiringManager = await tp.system.suggester(["First Name", "Hiring Manager"], ["First Name", "Hiring Manager"])
 if (hiringManager = "First Name") {
	 hiringManager = tp.system.prompt("Enter first name");
	 } else {
		 hiringManager = "Hiring Manager";
			 }
let companyName = await tp.system.prompt("Company Name");
 -%>
<% dateValue %>
<%companyName%>
RE:  <%positionName%>

Dear <%hiringManager%>,

EDIT: never mind. Forgot it’s == and not =.

1 Like

Yea. I am sorry that I must have kind of skipped the end part of your help request after seeing you were looking for a popup. I have been making heavy use of this functionality in my template usage lately and was excited to share it with you.

You could perhaps have a template with links instead of variables. And then try to use the functionality that creates a new notes with the matching names to the corresponding links. And then have the rename functionality let you rename each of these values thus updating the links to them in the initial note first generated. At that point you could just copy the note content while in Reading View and paste it into a new note and delete all the notes generated in order to make this work, so that everything is clear for next time.

It looks like you already understand this stuff more than me, but in the file module section of the Templater documentation these different functions I referenced in this workaround are described.

Good luck! Sorry if I wasted your time. Thanks.

No, not at all. You gave me the right direction- thank you for that! I appreciate the help and you definitely didn’t waste my time. In fact you saved me hours of searching

1 Like

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