If you have one or two placeholders in a note, and want to replace them with values using the Insert Text At Placeholder In Note action (or its Daily Note sibling), you’d use one action block per placeholder.
But what if you have 3 placeholders, or 10? Let’s consider this is note:
## My note
Today is %%date%%.
I feel %%mood%%.
The file path of this note is %%filepath%%.
Here, we’d have to use 3 separate Insert Text At Placeholder In Note actions, all with the same configuration.
There’s a better technique: Use Shortcuts’ built-in Dictionary action to declare our placeholder/replacement pairs, and a loop to iterate through them one at a time. (A “dictionary” refers to a data structure holding key/value pairs.)
Here’s a quick demo workflow which creates the note, sets up a list of key/value pairs (= placeholder/replacement pairs), then loops over that dictionary and inserts them one by one.
-
Set up note body as described above.
-
Create Note in my vault (its name is “Testbed”, change it your vault name), and use the note body as initial content.
-
Set up a dictionary with a key/value pair for each replacement:
- Key:
%%date%%
, value: the built-in “Current Date” variable. - Key:
%%mood%%
, value: “fine” - Key:
%%filepath%%
, value: the result of the “Create Note” action
-
Repeat with Each, using the dictionary’s keys. For that, insert the dictionary variable (result of the previous action), click it, and pick the “Keys” property. Now inside this loop construct, in every iteration the variable “Repeat Item” will contain a single dictionary key.
4.1. For readability, Set Variable “Placeholder” to the repeat item, i.e. the dictionary key.
4.2. A Get Dictionary Value action reads the value for the current key out of the dictionary.
4.3. For readability, Set Variable “Replacement” to the dictionary value from (4.2).
4.4. And finally, the Insert Text At Placeholder In Note action replaces the placeholder in the note with the actual value.
That’s it! The Dictionary handling might feel a bit weird at first, but iterating over the list of keys (4) and then separately looking up the values (4.2) works well.
Also, you could easily get rid of the “Set Variable” blocks (4.1 & 4.3) if you want to boil it down even more — I’ve added them for readability only.