I’m maintaining a javascript page and I’m just wondering what surrounding a variable with this will do?
<%= variable %>
I tried searching but wasn’t able to find anything relevant, so I’m sorry if this has been answered already! =)
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
These are ERB-style tags. They’re used in a variety of languages and formats, generally they are used to input simple variables into the page or do some logic on the variables passed to the page.
Seeing as it’s a Javascript page, you might want to check out the documentation for underscore.js’s templating engine, it will give you a good idea what’s going on.
http://underscorejs.org/#template
Another SO page that explains the differences between <%- %>, <%= %>, and <% %> tags in Underscore:
Boolean checks in underscore templates
Interpolate will put in the element as text (not HTML), escape will allow you to embed HTML, and evaluate will run what’s inside that as JS.