Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escaping overlay vars (mustache variables) inside template files #19

Closed
posilva opened this issue May 5, 2017 · 2 comments
Closed

Escaping overlay vars (mustache variables) inside template files #19

posilva opened this issue May 5, 2017 · 2 comments

Comments

@posilva
Copy link

posilva commented May 5, 2017

Hi

How to use bbmustache to allow to scape mustache variables, what I want is:

  • I have a file (my_template_sys.config.tpl) that has overlay vars, for example, we always use a config like: {environment, {{environment_var}}}.
  • When I run rebar3 new my_template myservice the environment config in sys.config is generated {environment, } because in the rebar3 template generation the variable is expanded and because does not exists in the context of the rebar3 template it will be replaced by “nothing”

Any sugestion?

Thank you

Pedro

@soranoba
Copy link
Owner

soranoba commented May 5, 2017

Discussion was done on slack.
https://erlanger.slack.com/archives/C055DJA49/p1493986463810192

@posilva
Copy link
Author

posilva commented May 5, 2017

Fixed using set delimiter: http://mustache.github.io/mustache.5.html

The trick is when we want to “escape” a variable we can change the delimiter right before, and after the variable declaration we change back to the default delimiter.

 { {{ name }}, [
        %% Application settings
        {environment, {{=<% %>=}}{{environment}}<%={{ }}=%>},
        {major, "{{=<% %>=}}{{major}}<%={{ }}=%>"},

        %% Network Settings
        {cluster_node_discover, {{=<% %>=}}{{cluster_node_discover}}<%={{ }}=%>},
        {server_interface, {{=<% %>=}}{{server_interface}}<%={{ }}=%> },
        { {{custom_parameter}}, param_value }
    ]}

With {{=<% %>=}} we change the delimiter as <% %>, then we declare the "escaped variable " {{cluster_node_discover}} and after that we set the default delimiter with <%={{ }}=%>

The template variable {{custom_parameter}} is not escaped and because the previous variables have the default delimiter set, this variable will be processed correctly by template engine.

I hope this helps

@posilva posilva closed this as completed May 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants