Is it possible to run find and replace with a list?

I have a list of placeholders that need to be replaced in certain cells within an RG but am trying to figure out how to loop through and replace all of the placeholder values. For example, let’s say I have text like so:

Good choice, {{User}}. What {{Product}} are you interested in today?

I want to run a find/replace that replaces all of the {{Placeholder}} values using a dynamic list pulled from a Placeholders data type, but the number of placeholders in the actual text may vary.

Thanks in advance.

1 Like

Set up the find&replace action in a Backend API Workflow

Then run ‘Schedule API Workflow on a list of things’ and select this list as the list of things to run it on.

@blurapps, thanks for the reply! Does that work automatically on an RG cell, or does it have to be triggered?

Oh wait.
I assumed you want to make these changes permanent and save it to your DB.
If that’s the case, the ‘Schedule API Workflow on a list of things’ approach will work.

I now realise that you simply want to display dynamic text in repeating groups.
In this case you can:

  1. apply the find/replace instructions to all the relevant text areas in the repeating group. (You only have to do it once and it will replicate across all items in the RG)
  2. this find/replace should have instructions to replace all the possible fields like {{User}} and {{Product}} that you may have
  3. in the find/replace, you assign the dynamic value with reference to the current cell. So for example:
    find/replace {{User}} with
    ‘current cell’s Creator’s Name’

Hope this helps.
Sorry for the confusion!

Use the toolbox list shifter

@blurapps, thanks for the reply, and no worries! That’s definitely closer, but the issue I’m trying to solve for is also whether or not it is possible to work with a dynamic list of placeholders from, say, a thing’s list column. This would let an end user create a custom placeholder without requiring that I manually define a replace expression. The current Bubble configuration requires that I do something like RGCell’s Text:replace:replace:replace etc., which is an absolute pain.

For example, let’s say I have the following:

Placeholders (Data Type):
{{CompanyName}} ABC Tech
{{CustomerCount}} 1000

I want to have an RG do a search for the list of Placeholders and replace all occurrences of those items in an RG as follows:

RG Cell #1:
Welcome to {{CompanyName}}'s homepage!
RG Cell #2:
Our company has serviced over {{CustomerCount}} customers worldwide and would love to partner with you.

I also want end users to be able to add their own placeholders and have the RG replace for those too rather than make that dependent on me writing an expression, so if a user added a new placeholder (e.g., {{Phone}}), the RG would automatically replace {{Phone}}.

Hope that makes sense!

@chris.williamson1996, thanks for the response! I’ve worked with the Toolbox a little but am curious how to make that fit my scenario. Any additional insight?

Yes, gotcha

I think the :find&replace:find&replace:find&replace method will work. Here’s how:

the list that your RG uses to populate itself seems to be a list of Users or Companies (depending on your database setup). And this contains the necessary data fields like Company Name.

So, for example, when you do find&replace (text to find: {{CompanyName}} and replace with 'CurrentCell’s User’s CompanyName ’
It will replace the placeholder with the dynamic data from the current cell’s item.
So in the RG, you can have a series of find&replaces. Ideally this is limited to say 10 (meaning that each user can’t have more than 10 custom placeholders)

For custom placeholders, here’s how I’d do it.
First, I’d create a data type called Placeholder.
The Placeholder data type contains ‘tag’ and ‘value’
‘tag’ being the thing to replace like {{Phone}} and ‘value’ being what it gets replaced with.
I’d also mod the User data type to have ‘Placeholders’ which is a list of ‘Placeholder’ items. But with the workflows, I’d limit the number of Placeholders that a User can have to 10 (since we limited the find&replaces earlier).
The User can set this up on a settings page. They can add or edit their Placeholders.
So maybe each placeholder has a dropdown next to it with the possible values that the user wants to add to it. Dropdown can contain ‘Company Name’, ‘User Name’, ‘Phone’, etc.
When the user picks one of these, the ‘Placeholder’ is updated to store that in the DB.

Then on your RG, you have
[text value] :find&replace:find&replace:find&replace… 10 times
each find&replace has these settings:
‘text to replace’ : Current Cell’s user’s Placeholders’s item#1’s tag
‘replace with’ : Current Cell’s user’s Placeholders’s item#1’s value
and you can do item # 3, 4, … 10 - for each find&replace

I think that should work.

1 Like

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