Skip to content

Commit

Permalink
Include advanced usage examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffrey-mu committed Apr 10, 2024
1 parent 29b076c commit cabe314
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/slot/body.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>body</div>
1 change: 1 addition & 0 deletions examples/slot/footer.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>footer</div>
15 changes: 15 additions & 0 deletions examples/slot/index.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

<div>
<%-include('./layout.ejs', {
body: include('./body.ejs'),
footer: include('./footer.ejs')
})%>
</div>

<hr>

<div>
<%-include('./layout.ejs', {
footer: include('./footer.ejs')
})%>
</div>
12 changes: 12 additions & 0 deletions examples/slot/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Advanced use of "include", fast layout, and dynamic rendering components.
*/

var ejs = require('../../lib/ejs');
var read = require('fs').readFileSync;
var join = require('path').join;
var path = join(__dirname, '/index.ejs');

var ret = ejs.compile(read(path, 'utf8'), {filename: path})({title: 'use slot'});

console.log(ret);
27 changes: 27 additions & 0 deletions examples/slot/layout.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>layout</title>
</head>

<body>
<div>
<h2><%=title%></h2>

<% if (typeof body !== 'undefined') { %>
<%- body %>
<% } else { %>
<p>This is the default body content.</p>
<% } %>

<div>description</div>

<%- footer %>
</div>

</body>

</html>

0 comments on commit cabe314

Please sign in to comment.