模板引擎jade与ejs语法

  1. 首先环境需要准备命令如下npm i jade ,npm i ejs,npm i fs
  2. jade的语法相对于ejs更有侵入性,破坏性这里写一个简单的列子来比较分析
html 
  head
  body
   div(class=['active','wrapper'])  hello this is jade

经过编译后是

<html>
 <head>head>
 <body>
   <div class="active wrapper">hello this is jadediv>
 body>
html>

这里使用的语法是属性可以写在()里面,包裹的值空一格就可以书写了

ejs书写格式:

 
 
 
   
hello this is jade

大家可以看到ejs没有啥改变。。

  1. jade中属性中特殊的部分一个是style它可以直接使json数据格式,还有一个是class它可以直接使用数组格式,但也可以使用普通的格式,如果想要都是json数据格式,可以用以下格式引用div&attributes({bacgroundColor:'red'})
  2. ejsjade在语法格式另一个不同在于
html
    head
    body
        div(class=['active','wrapper'],style={height:'100px'}) #{name}
        div&attributes({
            backgroundColor:'red'
        })
        -for(let i=0;i
  <html>
  <head>head>
  <body>
    <div class="active wrapper">hello this is jadediv>
    <%for(let i=0;i<3;i++)%{>
    <%include a.txt%>
    <%}%>
  body>

你可能感兴趣的:(前端)