jade template tag bracket percentage definition

被刻印的时光 ゝ 提交于 2019-12-11 17:07:40

问题


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') &times;
      |<%= 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!