From 59b53bdbcfb45b4953905e858eb972b619d1ac44 Mon Sep 17 00:00:00 2001 From: FireIsGood Date: Thu, 16 May 2024 15:09:57 -0700 Subject: [PATCH] fix: ejs format Added ignores to some code blocks and fixed up the table code block formatting --- source/_posts/ejs.md | 250 +++++++++++++++++++++---------------------- 1 file changed, 124 insertions(+), 126 deletions(-) diff --git a/source/_posts/ejs.md b/source/_posts/ejs.md index 89f0d64..534a253 100644 --- a/source/_posts/ejs.md +++ b/source/_posts/ejs.md @@ -8,22 +8,27 @@ tags: - Framework categories: - Programming -intro: EJS(Embedded JavaScript) is a simple templating language that lets you generate HTML markup with plain JavaScript. +intro: + EJS(Embedded JavaScript) is a simple templating language that lets you generate HTML markup with plain JavaScript. plugins: - copyCode --- -Get Started { .cols-3 } ------------ + + +## Get Started { .cols-3 } ### Hello world #### install -``` -npm install ejs + +```shell +$ npm install ejs ``` #### hello.ejs + + ```html <% if (user.email) { %>

<%= user.email %>

@@ -31,81 +36,79 @@ npm install ejs ``` #### CLI + ```shell $ ejs hello.ejs -o hello.html ``` - - ### Render with Data -``` -let ejs = require('ejs'); +```js +let ejs = require("ejs"); -let people = ['geddy', 'neil', 'alex']; +let people = ["geddy", "neil", "alex"]; let tpl = '<%= people.join(", "); %>'; -let html = ejs.render(tpl, {people: people}); +let html = ejs.render(tpl, { people: people }); console.log(html); ``` -Pass EJS a template string and some data. - +Pass EJS a template string and some data. ### Browser Support -``` +```html ``` + Use ejs in a script tag. - - ### Variables + | | | -|--------------|----------------------------------| +| ------------ | -------------------------------- | | `<%= var %>` | Prints the value of the variable | | `<%- var %>` | Prints without HTML escaping | - ### CLI Render and specify an output file. + ```shell $ ejs hello.ejs -o hello.html ``` Feed it a template file and a data file + ```shell $ ejs hello.ejs -f data.json -o hello.html ``` - - ### Comments + ```html <%# This line will denote a comment %> ``` ---------- + +--- + + ```html <%# This is a multi-line EJS comment. It can span multiple lines, - but will not be displayed - in the final HTML output. + but will not be displayed + in the final HTML output. %> ``` +### Method {.col-span-2} - - -### Method - -``` -let ejs = require('ejs'); +```js +let ejs = require("ejs"); let template = ejs.compile(str, options); template(data); @@ -114,13 +117,11 @@ template(data); ejs.render(str, data, options); // => Rendered HTML string -ejs.renderFile(filename, data, options, function(err, str){ - // str => Rendered HTML string +ejs.renderFile(filename, data, options, function (err, str) { + // str => Rendered HTML string }); ``` - - ### Including Files ```html @@ -132,8 +133,10 @@ Include a template with data: ```html <% include('header', { title: 'My Page' }) %> ``` ------------- +--- + + ```html