lightncandy icon indicating copy to clipboard operation
lightncandy copied to clipboard

Possible to access parsed variables?

Open jdlrobson opened this issue 5 years ago • 0 comments

This is possibly a feature request but hopefully it's already possible.

Given a template

<div>
  <p>{{#x}}{{value}}{{/x}}</p>
  <p>{{msg-foo}}</p>
</div>

Is there a method that can parse the template to predict the keys it uses?

E.g. in this case such a function would return.

['msg-foo', 'x']

My use cases are

  1. throw an error when certain variables are passed to the template renderer e.g. if i dont pass a key foo to the template it should throw an error
  2. i want to programmatically define template variables. For example any template key prefixed with msg- would be substituted beforehand e.g.
$templateData =[];
foreach($keysPrefixedWithMsg as $key){
$templateData[$key] = generateDataValue($key):
}

Let me know if I am not explaining well!

Thanks in advance!

jdlrobson avatar May 29 '20 01:05 jdlrobson