问题
I was reading the following jade code in drywall signup page and not sure about what the appearances of <% <%= means ? Can any one tell me ?
script(type='text/template', id='tmpl-signup')
form
div.alerts
|<% _.each(errors, function(err) { %>
div.alert.alert-danger.alert-dismissable
button.close(type='button', data-dismiss='alert') ×
|<%= err %>
|<% }); %>
div.form-group(class!='<%= errfor.username ? "has-error" : "" %>')
label.control-label Pick a Username:
input.form-control(type='text', name='username', value!='<%= username %>')
span.help-block <%= errfor.username %>
div.form-group(class!='<%= errfor.email ? "has-error" : "" %>')
label.control-label Enter Your Email:
input.form-control(type='text', name='email', value!='<%= email %>')
span.help-block <%= errfor.email %>
div.form-group(class!='<%= errfor.password ? "has-error" : "" %>')
label.control-label Create a Password:
input.form-control(type='password', name='password', value!='<%= password %>')
span.help-block <%= errfor.password %>
div.form-group
button.btn.btn-primary.btn-signup(type='button') Create My Account
回答1:
<% and %> denote a block of code which will be interpreted as javascript, and will be executed before the template is rendered. For instance, the following block
input.form-control(type='text', name='email', value!='<%= email %>')
Will insert the variable 'email' into the rendered html, so that the value of the textbox will equal to that variable. Similarly, forEach loops, and IF statements function just as they would in plain JavaScript when inserted into a <% %> block
来源:https://stackoverflow.com/questions/28256371/jade-template-tag-bracket-percentage-definition