diff --git a/examples/slot/body.ejs b/examples/slot/body.ejs new file mode 100644 index 00000000..cb74d9e8 --- /dev/null +++ b/examples/slot/body.ejs @@ -0,0 +1 @@ +
body
diff --git a/examples/slot/footer.ejs b/examples/slot/footer.ejs new file mode 100644 index 00000000..27dee2fa --- /dev/null +++ b/examples/slot/footer.ejs @@ -0,0 +1 @@ +
footer
diff --git a/examples/slot/index.ejs b/examples/slot/index.ejs new file mode 100644 index 00000000..6aa8ff5c --- /dev/null +++ b/examples/slot/index.ejs @@ -0,0 +1,15 @@ + +
+<%-include('./layout.ejs', { + body: include('./body.ejs'), + footer: include('./footer.ejs') +})%> +
+ +
+ +
+<%-include('./layout.ejs', { + footer: include('./footer.ejs') +})%> +
diff --git a/examples/slot/index.js b/examples/slot/index.js new file mode 100644 index 00000000..de3ce178 --- /dev/null +++ b/examples/slot/index.js @@ -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); diff --git a/examples/slot/layout.ejs b/examples/slot/layout.ejs new file mode 100644 index 00000000..549e70a3 --- /dev/null +++ b/examples/slot/layout.ejs @@ -0,0 +1,27 @@ + + + + + + + layout + + + +
+

<%=title%>

+ + <% if (typeof body !== 'undefined') { %> + <%- body %> + <% } else { %> +

This is the default body content.

+ <% } %> + +
description
+ + <%- footer %> +
+ + + +