How to use the render function from ejs

Find comprehensive JavaScript ejs.render code examples handpicked from public code repositorys.

243
244
245
246
247
248
249
250
251
252
```html
<div id="output"></div>
<script src="ejs.min.js"></script>
<script>
  let people = ['geddy', 'neil', 'alex'],
      html = ejs.render('<%= people.join(", "); %>', {people: people});
  // With jQuery:
  $('#output').html(html);
  // Vanilla JS:
  document.getElementById('output').innerHTML = html;
fork icon781
star icon0
watch icon121

55
56
57
58
59
60
61
62
63

```
<script src="ejs.js"></script>
<script>
  let people = ['geddy', 'neil', 'alex'];
  let html = ejs.render('<%= people.join(", "); %>', {people: people});
</script>
```
Use ejs in a script tag.
fork icon462
star icon0
watch icon25

+ 5 other calls in file

0
1
2
3
4
5
6
7
8
9
10
const ejs = require('ejs');
const fs = require('fs');
const ahaReactConfig = require('./config');


const templateFile = fs.readFileSync('redirect.ejs', 'utf-8');
const html = ejs.render(templateFile, { version: ahaReactConfig.version });
try {
  fs.mkdirSync('gh-pages-root');
} catch(e) {
  //ignore
fork icon1
star icon4
watch icon0

33
34
35
36
37
38
39
40
41
42
  $("#js-title").text(data.title)
  fields.forEach(function (field) {
    field.ids = ids
    var type = field.type
    var dom = tpl[type]
    var elem = ejs.render(dom, field)
    $("#js-content").append(elem)
  })
  componentHandler.upgradeDom()
})
fork icon1
star icon4
watch icon3

+ 3 other calls in file

43
44
45
46
47
48
49
50
51
52
if (extname(filePath) !== '.html') {
    filePath += '.html';
}
debug('saveReport -> filePath %o', filePath);
debug('saveReport -> results %o', results);
writeFileSync(filePath, ejs.render(
    readFileSync(normalize(join(__dirname, 'assets', 'index.html')), 'utf8'),
    { results, title, inPackage },
    {
        root: join(__dirname, 'assets'),
fork icon1
star icon2
watch icon2

9
10
11
12
13
14
15
16
17
18
19
const { PrismaClient } = require("@prisma/client");
const client = new PrismaClient();


app.get("/", (request, response) => {
    const index = fs.readFileSync("index.ejs", "utf-8");
    const html = ejs.render(index, {
        warning: "",
    });
    response.send(html);
});
fork icon3
star icon1
watch icon3

+ 35 other calls in file

2
3
4
5
6
7
8
9
10
11
12
const CopyPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ejs = require('ejs');


function transformHtml(content) {
    return ejs.render(content.toString(), {
        ...process.env
    });
}

fork icon0
star icon1
watch icon0

271
272
273
274
275
276
277
278
279
280
```html
<div id="output"></div>
<script src="ejs.min.js"></script>
<script>
  var people = ['geddy', 'neil', 'alex'],
      promise = ejs.render('<%= people.join(", "); %>', {people: people});
  promise.then(function (html) {
    // With jQuery:
    $('#output').html(html);
    // Vanilla JS:
fork icon0
star icon1
watch icon0

2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755


var ejs = require('ejs');




module.exports = function template(str, data) {
    return ejs.render(str, data);
};




// Workaround for IE 8's lack of support
fork icon1
star icon0
watch icon1

+ 4 other calls in file

1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
  app: app,
  element: element,
  filenamify: filenamify,
}
const templateString = fs.readFileSync(template, 'utf8')
const rendered = ejs.render(templateString, data, { async: false })
if (output) {
  const outputRendered = ejs.render(output, data, { async: false })
  fs.ensureFileSync(outputRendered)
  fs.writeFileSync(outputRendered, rendered, { encoding: 'utf-8' })
fork icon0
star icon1
watch icon1

+ 2 other calls in file

90
91
92
93
94
95
96
97
98
99
    return fs.readFileSync(name);
  }

  // 其他文件用 ejs 渲染返回
  const template = fs.readFileSync(name, "utf-8");
  return ejs.render(template, data);
}

// 将相关配置提取到 Generator 实例的 pkg 变量。
extendPackage(fields, options = {}) {
fork icon0
star icon0
watch icon1

+ 3 other calls in file

59
60
61
62
63
64
65
66
67
68
69
var data = {msg:'初期表示'};


//TOPページ
function indeX_render(req,res,url_parts){
	//既にロード済のページにレンだー
	var content = ejs.render(index_page,{
		title:'indexタイトル'
	});
	content = content.replace('1ss11','置換しました');
	//パラメータを取得してcontentに追記
fork icon0
star icon0
watch icon1

+ 11 other calls in file

81
82
83
84
85
86
87
88
89
90
    return fs.readFileSync(name)
  }

  // 其他文件用 ejs 渲染返回
  const template = fs.readFileSync(name, 'utf-8')
  return ejs.render(template, data)
}

extendPackage (fields, options = {}) {
  const pkg = this.generator.pkg
fork icon0
star icon0
watch icon1

+ 4 other calls in file

1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
  filenamify: filenamify
}
const templateString = fs.readFileSync(template, 'utf8')
const rendered = ejs.render(templateString, data, {async: false})
if (output) {
  const outputRendered = ejs.render(output, data, {async: false})
  fs.ensureFileSync(outputRendered)
  fs.writeFileSync(outputRendered, rendered, {encoding: 'utf-8'})
  ipcRenderer.send('console-log', `[StarUML] ${outputRendered}`)
} else {
fork icon0
star icon0
watch icon1

+ 11 other calls in file

60
61
62
63
64
65
66
67
68
69
70
71
72
73
let longWarningAlreadyShown = false;


module.exports = function(opts = {}) {
  opts = Object.assign({}, defaultOpts, opts);


  opts.loader = ejs.render(opts.loader, opts);


  const urlLoaderPrefix = opts.urlLoaderScheme + ":";


  let workerFiles;
fork icon0
star icon0
watch icon0

+ 4 other calls in file

41
42
43
44
45
46
47
48
49
50
51
52
  return google.gmail({ version: 'v1', auth: oauth2Client })
}




function createMessage(sender, emails, subject, data, template) {
  const rendered_html = ejs.render(template, {
    ...data,
    company: {
      ...data.company,
      domain: addhttps(data.company.domain.replace('http://', 'https://'))
fork icon0
star icon0
watch icon0