EJS template

   EJS is a simple template language, help us take advantage of common JavaScript code generated HTML page. EJS no complicated rules of grammar, nor a re-iteration and control of grammar, and some just plain JavaScript code only

You can use the browser environment

 

1 <script src="ejs.js"></script>
2 <script>
3     var people = ['geddy' , 'neil' , 'alex'],
4         html = ejs.render('<%= people.join(",");%>',{people:people});
5 </script>

Node can be used in environments

The EJS installed using npm current project
npm install ejs --save-prod

The use EJS templates and template syntax to write the data to show the number of pages compiled method as a parameter passed to the EJS offers, the final output HTML.

. 1 const = EJS the require ( 'EJS' );
 2  
. 3  // to display data pages 
. 4 const Colors = [ 'Red', 'Green', 'Blue' ];
 . 5  
. 6  // use the template grammar written EJS 
. 7 const Template = `
 . 8      <UL>
 . 9           <colors.forEach% ((value, index) => {%>
 10                  <Li> <% =% value> </ Li>
 . 11           <%})%>
 12 is      </ UL>
 13 is  `        
 14  
15  // the HTML code that + = EJS template data 
16 const = ejs.render HTML (template, Colors {});         

 

 



















Guess you like

Origin www.cnblogs.com/jiashuhua/p/12038999.html
Recommended