Mustache Prompt

Mustache Prompt works with templates written in the Mustache template format. It will automatically detect and prompt you for the values of all the variables in your template, and then create a new draft using the data you entered.

It supports type annotations for dates, booleans, and arrays of strings. Try running the action on a draft containing the example text below to see how it works. For more information, read my blog post on this action.

Here is a basic {{text_variable}}.

{{bool:#boolean_variable}}
Here is a paragraph that will only display if boolean_variable is true.
{{/boolean_variable}}

{{^boolean_variable}}
Here is a paragraph that will only display if boolean_variable is false.
{{/boolean_variable}}

{{#comma_separated_strings}}
Here is a paragraph that is repeated for each item in the array comma_separated_strings. The current item is {{.}}.
{{/comma_separated_strings}}

Here is a date: {{date:date_variable}}.
Here is the same date three days later: {{date_variable+3d}}
Here is the same date one week ago: {{date_variable-1w}}
Here is the same date in seven months’ time: {{date_variable+7m}}
Here is another date that is offset without the original date being shown: {{date:another_date+3w}}

A little tease as well: I actually built this as part of an update to one of my most popular actions. More on that soon…

4 Likes

Feedback welcome. For those of you who know JavaScript, here’s the code. Feel free to make a pull request.

3 Likes

Glad someone found a use for the Mustache features. I admit switching completely to Mustache was a feature I had hoped to build into Drafts when moving to Drafts 5, but it didn’t make the cut (major migration woes).

2 Likes

Can you synopsise what Mustache brings? (Yes I will look it up but drip feed to the Public can’t hurt.)

Wow, this is super cool! :clap:

I’d basically been trying to recreate something like this for “template” notes I had saved, but this is a 100x better than my quick hacks.

Really, really cool work, @pdavisonreiber. I’ll be using this a ton.

2 Likes

I had also started work on creating this exact idea, but am terrible at JavaScript. Thank you so much!!

2 Likes

First of all this is great. But when I run the example script a new draft is not created. The script looks like it should work, what am I missing?

That’s odd, not sure why that would be. I’ve just run it myself by copying and pasting from above and it seemed to work. If nothing happens when you run the action that usually means there is an error in the Mustache tags somewhere, e.g. invalid variable name with spaces etc.

Thank you, I have just copied and pasted again and it is working. For me there was a typo in the first copy.
This {{^boolean_variable}} was this {{boolean_variable}}.
Now it’s working

1 Like

You’ve prompted me to add some better error messages, rather than just silently failing. I’ve pushed this change to the Action Directory if you want to re-install.