handlebars-lang / handlebars.js

Minimal templating on steroids.
http://handlebarsjs.com
MIT License
17.96k stars 2.04k forks source link

Is it possible to disable control flow statements? #1967

Closed j-000 closed 1 year ago

j-000 commented 1 year ago

Hi

Is there a way to disable access to control flow (if, else, unless, with, etc.)?

For my use case, I need a templating engine that provides efficient keyword replacement ({{ keyword }}) but I don't want users to be able to use control flow statements.

Essentially, if the control flow is disabled, then when evaluating the template the engine would ignore the control flow statements.

const userTemplate = '<h1>Title {{ title }}</h1>{{#if condition}} show {{/if}}';  
const template = Handlebars.compile(userTemplate);
const context = { title: 'My App', condition: true};

const result = template(context);  // currently: '<h1>Title My App</h1>show'
const result = template(context);  // expected with control flow disable:  '<h1>Title My App</h1>{{#if condition}} show {{/if}}' // gets ignored. 

I couldn't find this on the docs.

Thanks Joao