ejs

Could not find include include file

一个人想着一个人 提交于 2019-11-30 09:02:02
问题 I'm running a simple server var express = require('express') var app = express() app.set('view engine', 'ejs'); app.use(express.static('public')) // home page request handler app.get('/', function (req, res) { res.render('home') }) // initializes request listener app.listen(process.env.PORT, process.env.IP, function(){ console.log("Server is listening"); }) When I make a GET request for the home page, run-time throws the following error Error: Could not find include include file. at

EJS: <%= versus <%-

有些话、适合烂在心里 提交于 2019-11-30 08:16:54
问题 I'm using EJS with a Node.js web server I'm building. I see many EJS examples that sometimes use <%= when outputting HTML or strings, while other examples (sometimes within the same template) use <%- . I tried to reference the EJS docs and getting started guide, but both gave no info about the <%- notation. Also, my Google search attempts yielded nothing useful. Thanks! 回答1: The version of EJS you're likely using in Node is not the same as the version you see on Google code; in the Node

Inside Express/EJS templates, what is cleanest way to loop through an array?

无人久伴 提交于 2019-11-30 08:06:34
I have an Express.js app set up using EJS templates. I successfully looped through an array with classic JS syntax: <% for (var i = 0; i < myArray.length; i++) { this = myArray[i]; // display properties of this } %> But I'm wondering, is there a cleaner way to do this? Specifically, can I use Underscore or Lodash to loop through with .each ? thank you You can use forEach method myArray.forEach(function(el, index) { // el - current element, i - index }); 来源: https://stackoverflow.com/questions/16153384/inside-express-ejs-templates-what-is-cleanest-way-to-loop-through-an-array

How can I use Underscore.js templates in conjunction with EJS?

自作多情 提交于 2019-11-30 07:30:22
问题 They both use the same syntax for inserting variables. For example if I want the following <%= username %> In my Underscore, my main EJS breaks because it tries to replace username and no such variable exists in the main page. 回答1: I think square brackets will work in EJS by default: [%= username %] And if you need to get fancier, the EJS github page describes how to create custom tags: var ejs = require('ejs'); ejs.open = '{{'; ejs.close = '}}'; I think that 2nd "fancier" part might be

call functions from with ejs templates on node

跟風遠走 提交于 2019-11-30 07:28:32
I am trying to create a non-javascript version of my web app using ejs on the server side. I pass into the template an object containing the app's state, and at one point I want to build a url using that state object. So basically I want to do something like <%=makeUrl(objectState.data[0])%> how can I make makeUrl callable from within ejs templates? Thanks edit: I know I can pass a function in as a parameter to the template, but is there a better way? in Express 3, they removed the concept of dynamic helpers. I believe that passing functions into the template via app.locals is in fact the

Interweave EJS and Javascript variables inside <% tags

人盡茶涼 提交于 2019-11-30 06:27:25
问题 I need to use a Javascript variable (defined in the front-end) in some EJS code, as follows: var selected = 1; <% for (var i=0; i < supplies.length; i++) { %> if (i == selected) { console.log(supplies); } <% } %> I'm using EJS, Express.js and socket.io. I could convert the Javascript variable to an EJS variable by sending a message to my Node.js server instance, but that's kind of silly... Is there a way to use Javascript variables inside EJS? EDIT: I want to access supplies, a javascript

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

☆樱花仙子☆ 提交于 2019-11-30 06:25:05
问题 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 lines <link rel="stylesheet" type="text/css" href="/css/style.css" /> <link rel="stylesheet" type="text/css" href="/public/css/style.css" /> Neither loads the css. I've gone into the developer's console noticed the type is set to 'text/html' instead of

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

若如初见. 提交于 2019-11-30 05:40:14
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'); %> doesn't work I am using ExpressJS with EJS as the template engine. I found another way of doing this, and I think it has some advantages. Don't polute your code exporting filters. Access any method without the need to export them all. Better ejs usage (no | pipes). On your controller, or view.js do this: var moment = require('moment'); exports

can I use EJS with AngularJS?

只愿长相守 提交于 2019-11-30 04:49:23
Hi I am new to AngularJS. I have great web app already running with JQuery and jQuery UI. Now I want to completely get rid of JQuery and am going to migrate to Angularjs because of its MVC (MVW) pattern. So my jQuery application is running with EJS for templates and entirely DOM manipulation. But when I think about Angular js, I have doubts. Can I still use EJS or not? So please guide me whether I can use or not. Another doubt is, let's assume I have list page. It is updated dynamically, and it will display 10 records first then based on user scroll, the next 10 records will be appended in the

Why is express telling me that my default view engine is not defined?

痴心易碎 提交于 2019-11-29 17:34:34
问题 I'm using nodejs and mongodb in the back end for an app I'm working on. I'm using express to test the app, and I'm trying to use ejs to render my html files. However, I'm having the issue of my default view engine not being defined. Here is my app.js: /** * Module dependencies. */ var express = require('express') , routes = require('./routes') , user = require('./routes/user') , http = require('http') , path = require('path'); var conf = require('./conf'); var app = express(); var mongoose =