Questions tagged [ejs]

"E" is for "embedded." EJS is a simple templating language that lets you generate HTML markup with plain JavaScript. No religiousness about how to organize things. No reinvention of iteration and control-flow. It's just plain JavaScript.

Embedded JavaScript (EJS) is a set of two open source libraries providing in-browser client side templates for web development and as a template system for node.js (including client-side template functionality). EJS uses <% %> or [% %] tags, executing any JavaScript within the tags. Adding an equals sign (<%= %>) causes the enclosed JavaScript to be evaluated, and the toString representation to be appended to the document.

The original client-side EJS has been subsumed into JavaScriptMVC, official support is offered at their forum (the old Google Groups group is no longer active).

Install via npm: npm install ejs.

References:

6440 questions
157
votes
20 answers

What is the proper way to check for existence of variable in an EJS template (using ExpressJS)?

On the EJS github page, there is one and only one simple example: https://github.com/visionmedia/ejs Example <% if (user) { %>

<%= user.name %>

<% } %> This seems to be checking for the existence of a variable named user, and if it…
Aashay Desai
  • 3,093
  • 3
  • 18
  • 16
142
votes
8 answers

Can I use conditional statements with EJS templates (in JMVC)?

and if yes, what is the syntax? My goal is to prepend an 's' to the word 'comment' when there is more than one. in an jQuery.ejs template in a JMVC app. The following breaks. I can't find any docs for conditionals... <%=commentsNumber%> comment<% if…
Regis Zaleman
  • 3,182
  • 6
  • 29
  • 30
122
votes
2 answers

What are the pros and cons of both Jade and EJS for Node.js templating?

Jade versus EJS, what are the pros and cons of each and what purposes are each designed for? Are there any other express-compatible template engines that are good and why?
HaoQi Li
  • 11,970
  • 14
  • 58
  • 77
120
votes
4 answers

Render a variable as HTML in EJS

I am using the Forms library for Node.js (Forms), which will render a form for me on the backend as so: var signup_form = forms.create({ username: fields.string({required: true}) , password: fields.password({required: true}) , confirm: …
MrJaeger
  • 1,606
  • 3
  • 15
  • 14
99
votes
31 answers

Error: Cannot find module 'ejs'

Here is my complete error: Error: Cannot find module 'ejs' at Function._resolveFilename (module.js:317:11) at Function._load (module.js:262:25) at require (module.js:346:19) at View.templateEngine…
Shamoon
  • 41,293
  • 91
  • 306
  • 570
93
votes
14 answers

Node.js - EJS - including a partial

I am trying to use Embedded Javascript renderer for node: https://github.com/visionmedia/ejs I would like to know how I can include another view file (partial) inside a .ejs view file.
jeffreyveon
  • 13,400
  • 18
  • 79
  • 129
87
votes
4 answers

Express and ejs <%= to render a JSON

In my index.ejs I have this code: var current_user = <%= user %> In my node I have app.get("/", function(req, res){ res.locals.user = req.user res.render("index") }) However, on the page I obtain var current_user = [object Object] and if…
piggyback
  • 9,034
  • 13
  • 51
  • 80
86
votes
8 answers

How to create global variables accessible in all views using Express / Node.JS?

Ok, so I have built a blog using Jekyll and you can define variables in a file _config.yml which are accessible in all of the templates/layouts. I am currently using Node.JS / Express with EJS templates and ejs-locals (for partials/layouts. I am…
Cory Gross
  • 36,833
  • 17
  • 68
  • 80
82
votes
12 answers

How can I include css files using node, express, and ejs?

I'm trying to follow the instructions to https://stackoverflow.com/a/18633827/2063561, but I still can't get my styles.css to load. From app.js app.use(express.static(path.join(__dirname, 'public'))); In my .ejs, I have tried both of these…
stealthysnacks
  • 1,091
  • 1
  • 12
  • 16
65
votes
9 answers

In EJS template engine, how do I "include" a footer?

Let's say I saved a snipplet of a footer. How do I "include" that in my current template?
TIMEX
  • 259,804
  • 351
  • 777
  • 1,080
64
votes
5 answers

Loop through JSON in EJS

I have codes in EJS below, <% for(var i=0; i <%= JSON.stringify(data)[i].id%> <% }…
Hammer
  • 8,538
  • 12
  • 44
  • 75
57
votes
13 answers

babel-preset-react-app, is importing the "@babel/plugin-proposal-private-property-in-object" package without declaring it in its dependencies

my issue is that I've tried to create a new react project and after a lot of issues with vulnerabilities I managed to solve some of them, one of the main instructions was adding this line: "overrides": { "@svgr/webpack": "$@svgr/webpack" …
Omri Ben Lulu
  • 721
  • 1
  • 2
  • 7
53
votes
10 answers

How to use node modules (like MomentJS) in EJS views?

To use MomentJS in views/custom.ejs, what is the correct way (if any)? Server side routes/index etc we can easily use require('moment'); etc and it works fine. Server Side (EJS views) views/custome.ejs, something like <% var m = require('moment');…
dmodulus
  • 1,003
  • 2
  • 9
  • 7
52
votes
6 answers

adding .css file to ejs

im working on node.js(express) with ejs and im not able to include a .css file to it.i tried the same thing seperately as a html-css duo and it worked fine...how can i include the same in my .ejs file. My app.js goes thus: var express =…
user-S
  • 3,019
  • 3
  • 16
  • 10
51
votes
10 answers

Accessing EJS variable in Javascript logic

I'm working on a Node.js app (it's a game). In this case, I have some code set up such that when a person visits the index and chooses a room, he gets redirected to the proper room. Right now, it's being done like this with Express…
Catherine Hwang
  • 980
  • 3
  • 9
  • 18
1
2 3
99 100