1

I'm making a tool that uses handlebars expressions/templates. The idea is for the user to specify a default value for each of the expressions in the template. What i'd like to have is an array of all the expressions in a certain html.

for ex:

 <div style="display:none;font-size:1px;color:#e9e9e9;line-height:1px;max-height:0px;max-width:0px;opacity:0;overflow:hidden;">
        {{striptags INTRO}}
 </div>
 {{INTRO}}
 <br />
 {{BODY}}
 {{#if UNSUBSECRET}}
 <div> you can unsub...</div>
 {{/if}}

The array then would be:

  • INTRO
  • BODY
  • UNSUBSECRET

Regex would be an option because I won't support any new helpers, but isn't there simply a way to get them all from the nodejs lib?

Stefanvds
  • 5,868
  • 5
  • 48
  • 72
  • I think this will help: [Regex for mustache-style double braces?](https://stackoverflow.com/questions/15502629/regex-for-mustache-style-double-braces/15502875) – erwineberhard Feb 08 '18 at 11:34

1 Answers1

0

It's not clear how you're passing data (e.g. are you taking user input, processing it server-side and returning it on a different view?). This helper can be used to create a set of objects:

{{#each userEntries}}
  {{@key}}:{{.}}
{{/each}}

Data:

{
  "userEntries": {
    "INTRO": "some dynamic value",
    "BODY": "some other value",
    "UNSUBSECRET": "and another value"
  }
}
  • you have misunderstood my question i'm afraid. I want to list all {{EXPRESSIONS}} that exist in a given template. so basically the other way around. i have a template, i want to know which 'expressions aka values' it takes – Stefanvds Jan 08 '18 at 04:50
  • Hmmm ok – I think I've got it. You want to know the names of each expression in the Handlebars template before the user views the template. Then, you want to create an array (server-side) with the values of each of the expressions. Yes? The idea is that you can process any Handlebars templates (before compilation) without knowing the {{EXPRESSIONS}} in the template – shagamemnon Jan 08 '18 at 04:57
  • yeah, i want a list of all {{EXPRESSIONS}} pulled out of the template – Stefanvds Jan 08 '18 at 05:34