From cabe3146ad964a1e98db7742abf435906ca79406 Mon Sep 17 00:00:00 2001 From: Jeffrey <1115378579@qq.com> Date: Thu, 11 Apr 2024 00:39:26 +0800 Subject: [PATCH] Include advanced usage examples --- examples/slot/body.ejs | 1 + examples/slot/footer.ejs | 1 + examples/slot/index.ejs | 15 +++++++++++++++ examples/slot/index.js | 12 ++++++++++++ examples/slot/layout.ejs | 27 +++++++++++++++++++++++++++ 5 files changed, 56 insertions(+) create mode 100644 examples/slot/body.ejs create mode 100644 examples/slot/footer.ejs create mode 100644 examples/slot/index.ejs create mode 100644 examples/slot/index.js create mode 100644 examples/slot/layout.ejs 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 %> +
+ + + +