In Mustache, it was possible to set custom delimiters. Example ([source](https://github.com/janl/mustache.js/#setting-in-templates)): ``` {{ default_tags }} {{=<% %>=}} <% erb_style_tags %> <%={{ }}=%> {{ default_tags_again }} ``` Explanation: * On the first and last line the default delimiters `{{` and `}}` are used. * Line 2 indicates that `<%` and `%>` should be used instead of `{{` and `}}`. * Line 3 uses the custom delimiters * Line 4 indicates that `{{` and `}}` should be set instead of `<%` and `%>`. This do not seems to work with handlebars. This [stackoverflow question ](https://stackoverflow.com/a/17642427/91497) propose an alternative to escape `{` and `}` in handlebar: `{{"{"}}` and `{{"}"}}`. Example in swagger templates (example from [`/modules/swagger-codegen/src/main/htmlDocs2/sample_js.mustache`](https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/htmlDocs2/sample_js.mustache#L22)). Mustache: ``` ...some text.. {{=< >=}}{<&dataType>}<={{ }}=> .. and more ....... ``` But this does'nt work with handlebar java: ``` ...some text.. {{"{"}}{{&dataType}}{{"}"}} .. and more ....... ```
Activity
jmini commentedon Mar 8, 2018
The solution needs to be documented here: https://github.com/swagger-api/swagger-codegen/wiki/Swagger-Codegen-migration-from-Mustache-and-Handlebars-templates.#custom-delimiters
jmini commentedon Mar 8, 2018
I do not know how handlebars works, but maybe it is possible to use a constant referenced somewhere:
HugoMario commentedon Mar 9, 2018
we can also add a new helper class to that and dealing the issue from java code. wdyt @jmini ?
jmini commentedon Mar 9, 2018
I am fine with any solution. I do not know mustache or handlebars well enough in order to have a meaningfull opinion.
I would apreciate if you could prepare the necessary infrastrure (or provide a detailed explanation on how helper class works).
Issue #33: added braces helper.
HugoMario commentedon Mar 15, 2018
@jmini i added a new helper to address this, can you please check if it works as expected?
in your last example you just need to use:
{{braces "left"}}{{&dataType}}{{braces "right"}}jmini commentedon Mar 15, 2018
This works as expected! Thank you.
I could migrate the
html2Codegen using this construct (see #41).Wiki page will be updated with the solution.