<% var percentage = (data.skills[i].rating / 10) * 100 %>
<div class="progress">
<% var style = `style=width: percentage%` %>
<div class="progress-bar color-1" role="progressbar" aria-valuenow="%= percentage %>"
aria-valuemin="0" aria-valuemax="10" <%= style %>>
<span><%= percentage %>%</span>
</div>
</div>
Add a comment
|
1 Answer
You need to use <%- for unescaped strings instead of <%= for style to work <%- style %>.
You forgot a < in front of %= here aria-valuenow="%= percentage %>
Also i'm not sure what you think this does style=width: percentage% since percentage% is just a string which will not be replaced by ejs engine.
So the correct code should look like bellow:
<% var percentage = (5 / 10) * 100 %>
<div class="progress">
<% var style = `style="width: ${percentage}px"` %>
<div class="progress-bar color-1" role="progressbar" aria-valuenow="<%= percentage %>"
aria-valuemin="0" aria-valuemax="10" <%- style %>>
<span><%= percentage %>%</span>
</div>
</div>
You can paste the code in this playground to see what the output is.
1 Comment
Dumitru Birsan
such a small thing but it has huge implications , i can't believe i've missed the difference between = and - for the past 6 months ...