Generating List Of Mustache Tags In A Template

Google falls over again looking for:

“generating list of mustache tags in a template”
“regular expression list of mustache tags in a template”
“grep list of mustache tags in a template”
“get list of mustache tags in a template”
“grep expression for mustache tags”

What am I trying to do? I have a Mustache template, and I want to pull out the list of tags I am using in it, because I need to filter a bigger chunk of JSON data to only contain those tags. This JSON data will eventually be used as the context that is then used to .render() the output.

Google needs to reinstate exact-quote indexing, the fuzzy searches of the past few years are making it really hard to find relevant links. (Yes, I probably should have the regex rules memorized, but this can’t be the first time someone’s been looking for this.)

For the record, the command I used to generate this list:

Update 2 March 2013:

The above command was perhaps a bit too simple, it gives the tags in the form of a list of “{{tag}}”.

To get rid of the mustache brackets, you have to run the point through sed.

In Python, the following regex will also give you all the tag names, sans brackets:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.