Creating user-specific templated documents

I’m relatively new to Bubble, but already have my app prototype up and running. I ran into something I don’t know how to do so I’m looking for advice.

I need to create documents for clients, where each client can set up a unique template and we would automatically populate the template for them from variables also unique to them. So the templates are a combination of plain text and variables. An example of how a template would look like:

This is a template for {{FirstName}}.

{{FirstName}} has a {{KindOfPet}} called {{PetsName}}.

I want to save these templates as text fields in the database on a per user basis.

Question 1 is regarding the creation of the template. Here is what I came up with:

The user can enter the text of the template in the multiline text field. Adding variables is done by selecting them from the dropdown above the text field, and clicking Insert.

What I don’t know is HOW I can insert the placeholder for the variable in the text field. i.e. when the user selects “First name” from the dropdown and clicks the Insert button, the placeholder text {{FirstName}} should be inserted into the text box below at the current cursor position. I know how to populate the dropdown and let the user select a variable, I just don’t know how to insert it into the text box.

Question 2 is about populating the template with the variables, i.e. output. Using the above example, here is what I have:

This template, created by the user:

This is a template for {{FirstName}}.

{{FirstName}} has a {{KindOfPet}} called {{PetsName}}.

… and these variables, associated with the user:

FirstName = Joe

KindOfPet = Cat

PetsName = Fluffy

… and to create the output, I need to replace the placeholders for the variables with the variables themselves, so I can populate a multiline text field for the user with this:

This is a template for Joe.

Joe has a cat called Fluffy.

So I would need to do some text replacement, but… how? Is there anything in Bubble that can do this?

This topic was automatically closed after 70 days. New replies are no longer allowed.