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

Is there a way to keep Template Strings From Being Processed? #1462

Open
Izzmo opened this issue Feb 13, 2016 · 6 comments
Open

Is there a way to keep Template Strings From Being Processed? #1462

Izzmo opened this issue Feb 13, 2016 · 6 comments
Labels

Comments

@Izzmo
Copy link

Izzmo commented Feb 13, 2016

Simple question: is it possible to keep template strings from getting processed?

I shouldn't have to do this:

replacements: [{
   from: 'something',
   to: '<script src="<ConfigurationManager.AppSettings("something")>"></script>'
},{
   from: 'ConfigurationManager.AppSettings("something")',
   to: '%=ConfigurationManager.AppSettings("something")%'
}]
@shama shama added the question label Feb 13, 2016
@nycdotnet
Copy link

The documentation for lodash indicates that \\ can be used to escape the open and close angle brackets.

https://lodash.com/docs#template

so for example:

replacements: [{
   from: 'something',
   to: '<script src="\\<%=ConfigurationManager.AppSettings("something")%\\>"></script>'
}]

@Izzmo
Copy link
Author

Izzmo commented Jun 27, 2016

@nycdotnet the problem is that those output like:

<script src="\<%=ConfigurationManager.AppSettings("something")%\>"></script>

instead of

<script src="<%=ConfigurationManager.AppSettings("something")%>"></script>

Not sure why it's keeping the extra slash in there.

@ArmorDarks
Copy link

It's most likely upstream issue. Did you try to test it with native lodash _.template(...)? Does it produce those slashes too?

@Izzmo
Copy link
Author

Izzmo commented Aug 5, 2016

@ArmorDarks Sort of.

This adds a slash (making it a single backslash outputs fine though..):

let x = _.template('test <%= test %>!');
x({ test: '<script src="\\<%=ConfigurationManager.AppSettings("something")%\\>"></script>' });

// output: "test <script src="\<%=ConfigurationManager.AppSettings("something")%\>"></script>!"

@ArmorDarks
Copy link

Oh, now I see why it doesn't work.

Here is example from docs:

// Use backslashes to treat delimiters as plain text.
var compiled = _.template('<%= "\\<%- value %\\>" %>');
compiled({ 'value': 'ignored' });
// ➜ '<%- value %>'

Please, note that you should wrap escaped template into template tags too to make it work.

_.template('\\<%- value %\\>')()
\\ returns `\<%- "value" %\>`

_.template('<%= "\\<%- value %\\>" %>')()
\\ returns `<%- value %>`

Though, what is really strange, while '<%= "\\<%- value %\\>" %>' works in lodash templates, Grunt for some reasons completely ignores escaping and trying to process whole template, which results in Warning: An error occurred while processing a template (value is not defined).

So, in the end of all, it's Grunt's issue.

@Izzmo
Copy link
Author

Izzmo commented Aug 5, 2016

@ArmorDarks thanks for writing that out, that helps. So, now, where in the Grunt code should this be fixed, do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants