As I wrote in the title. In Ejs what's the difference between <%=
, <%
and <%-
? for example I saw this code <% include ../partials/header.ejs %>
, and then there is this code <%= title %>
. I also saw <%-
somewhere but cannot find a code example anywhere. So what's the difference? When do I use which?
I found this but it's for ruby on rails
Difference between <% %> and <%= %> in RoR
<%= Outputs the value into the template (HTML escaped) <%- Outputs the unescaped value into the template.
Yes, you cant: if it is on server.
When using the default view engine ( ejs ), Sails supports the use of partials (i.e. "view partials"). Partials are basically just views that are designed to be used from within other views. They are particularly useful for reusing the same markup between different views, layouts, and even other partials.
Data passed from the server is sent to the EJS file and then we can access that data using the below line and it will give that data to h, p, or another text tag. Now you can perform any operation on the data variable which has the same value as EJS passed data variable.
The following is from ejs docs (tag section):
- <% 'Scriptlet' tag, for control-flow, no output
- <%= Outputs the value into the template (HTML escaped)
- <%- Outputs the unescaped value into the template
See the difference between escaped and unescaped html here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With