ejs

What is the proper way to loop through an array in an EJS template after an AJAX Call (using ExpressJS)?

萝らか妹 提交于 2019-12-05 00:15:22
So I am trying to loop through an array of objects that I got from an http call using to my internal API using the request module/package. So far, I am able to get my data back from the API and DISPLAY the full object on my page. I would like to display it on my page and loop through it using the EJS templating system. I know I can use AngularJS for frontend stuff, but I would like to see how far I can go with only server-side. So below is my code: server.js // Prepend /api to my apiRoutes app.use('/api', require('./app/api')); api.js var Report = require('./models/report'); var express =

Script won't run from ejs file in nodejs application

混江龙づ霸主 提交于 2019-12-04 20:32:31
I'm trying to make a webpage display a chart using nodejs, express, mysql, and ejs, but I clearly don't understand something about how ejs / javascript etc. works. I need a script to run that sets up a chart (from chart.js module) yet it is not outputting any sort of chart whatsoever. What I tried: placing console.log() messages in the script to see if my code within the script was the problem. There was no output to the console so I'm convinced the script itself is not running placing paragraph tags in the same file above the scripts, which displayed normally, showing that the file is still

How to: Use ejs without express

别等时光非礼了梦想. 提交于 2019-12-04 18:57:53
问题 I'm starting with node in general, and I'm attempting to do a site without express. I would none the less want to use ejs to inject my html and this is where my problem is... How do I attach the ejs.render(...) to the response? PS: I know it might be a better option to use express, but I want to know how it works underneath before bridging it. Something like: var ejs = require("ejs"); function index (response, request, sequelize) { response.writeHead(200, {"Content-Type": "text/html"}); test

NodeJs - esc is not a function

霸气de小男生 提交于 2019-12-04 18:52:35
问题 I got a weird issues when trying to render an .ejs file at this specific lines TypeError: /home/me/nodeapp/app/views/default/page/connection.ejs:66 64| <div class="col s12 l8"> 65| <ul class="collapsible popout" data-collapsible="accordion""> >> 66| <%- include ../api_html/connection/connection_list.ejs %> 67| </ul> 68| </div> Here is the error esc is not a function I really don't understand from where this error is coming from. I'm not using an esc function the ../api_html/connection

Datetime formatting / customization in ejs

你。 提交于 2019-12-04 18:47:06
问题 I show date by this in ejs <%= new Date();%> it give me result Tue Feb 02 2016 16:02:24 GMT+0530 (IST) But I need to show as 19th January, 2016 How can I do this in ejs? 回答1: You can use moment In your controller, var moment = require('moment'); exports.index = function(req, res) { res.render('index', { moment: moment }); } In your html, <html> <h1><%= moment().format('Do MMMM, YYYY'); %></h1> </html> 回答2: You don't need moment js, you can simply use this <%= new Date().getFullYear();%> 回答3:

Convert Jade to EJS

旧时模样 提交于 2019-12-04 17:21:12
Can anyone please help by convert this Jade to EJS? extends layout block content h1. User List ul each user, i in userlist li a(href="mailto:#{user.email}")= user.username There is no block but an include logic available in EJS. Split up the "main layout" that way that you can include a header and footer (or whatever suits your needs). The iteration is expressed in plain JavaScript escaped in sequences of <% ... %> . Using <%= ... %> directly outputs the referenced var. Your resulting EJS code might look as follows: <h1>User List</h1> <ul> <% for (var i = 0; i < user.length; i++) { %> <li><a

EJS.JS ReferenceError: title not defined

99封情书 提交于 2019-12-04 17:19:15
I am having an issue with a script in express. I am calling a function that renders a view, on the success of another function. In this project I am utilizing angular, node, express, and ejs as view engine. When I render the view, I unfortunately receive an ejs error of the following: ReferenceError: /Users/emilywfrancis/Desktop/nodejs-angularjs-sequelizejs/views/about.ejs:5 3| <html ng-app="app"> 4| <meta charset="utf-8"> 5| <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/3.1.0/css/font-awesome.min.css" /> 6| <% include header %> 7| <% include navbar %> 8| <body>

Using interpolation within Node.js EJS includes

寵の児 提交于 2019-12-04 16:28:12
问题 My Express app is using EJS, and my views directory looks like this: ./views ./contents home.ejs ./includes header.ejs footer.ejs layout.ejs I'm trying to load home.ejs in my layout.ejs view conditionally based on a local variable named contents in my routes/index.js. That file looks like this: /* * GET home page. */ exports.index = function(req, res){ res.render('index', { title: 'Home', contents: 'home.ejs' }); }; Ideally I could simply write (in layout.ejs): <% include '/contents' +

How do I stop getting this ReferenceError in node.js?

不打扰是莪最后的温柔 提交于 2019-12-04 15:08:52
183| }); 184| >> 185| <% if(just_registered) { %> 186| alert("Welcome!"); 187| <% } %> 188| just_registered is not defined Basically, I want to say: if just_registered is defined and is true, then alert. However, I want want to set everything to false...I just want to leave it undefined (i have like 100 variables) <% if(typeof just_registered !== "undefined") { %> Basically your checking whether a local variable exists. To do this you have to use the typeof operator since accessing just_registered which is an undeclared local variable creates a reference error. This is best compared to var foo

Refresh section of a page using EJS and Express

纵然是瞬间 提交于 2019-12-04 14:54:05
问题 I have a checkbox that when pressed call a function that does a GET request. Based on the selection I want to display extra checkboxes on the same page. At the moment this is the code I have so far: Client side function selectedHouse(house) { if(house.checked){ $.get('/', {data: house.value}); } } Server side var routing = function (nav, houses) { router.route('/') .get(function (req, res) { var rooms = []; rooms = getRooms(req.query.data); console.log(rooms); res.render('index', { title: