ejs

Express layouts error - variable not defined

旧时模样 提交于 2019-12-12 22:18:06
问题 I am using express-ejs-layouts and am seeing the following error in the console log: >> 5| <title><%= title %></title> title is not defined I do indeed have the following element defined in my layout.ejs file: <title><%= title %></title> I am populating this variable from one of my route files: router.get('/', function(req, res) { res.render('index', { title : 'Express' }); }); Any idea what I am missing? Thanks! 回答1: I figured this out. There was another variable (description) that was not

how to format a date in embeddedjs

喜欢而已 提交于 2019-12-12 12:14:29
问题 app.js app.get('/user.html', function(req, res){ dbConnect.collection("users").find().toArray(function(err, docsData) { res.render('user', { data: docsData, title: "EJS example", header: "Some users" }); }); }); user.html <% data.forEach(function(user){ %> <tr> <td> <%= user.date %> </td> </tr> <% }) %> output is 2014-12-24T09:47:07.436Z this is the value coming from mongodb. I want to format this to Dec-24-2014. How to format it in embeddedjs. 回答1: You can use toDateString() to better format

How can I use if statement in ejs?

只谈情不闲聊 提交于 2019-12-12 08:43:14
问题 I have a page that makes a foreach and show some photos like this <% imgs.forEach(function(img) { %> <img src="uploads/<%=user.username%>/screenshots/<%= img %>"> <% }); %> And I want make a if statement because, in case that not photos to show gives a message like this: "no photos uploaded" 回答1: Something like this: <% if(imgs.length > 0){ %> <% imgs.forEach(function(img) { %> <img src="uploads/<%=user.username%>/screenshots/<%= img %>"> <% }); %> <% } else{ %> <p>no photos uploaded</p> <% }

how to use both ejs and jade in one nodejs & express project?

女生的网名这么多〃 提交于 2019-12-12 08:09:05
问题 I want to use ejs for partials and use jade for individual pages, how to use both in one nodejs & express project? 回答1: It 's easy to find the way in expressjs api docs and consolidate.js at github Reference the express.js doc fragment below, please app.engine(ext, callback) Register the given template engine callback as ext By default will require() the engine based on the file extension. For example if you try to render a "foo.jade" file Express will invoke the following internally, and

how to use includes/partials in Rails 3 Backbone ejs.jst files

房东的猫 提交于 2019-12-12 05:44:52
问题 I'm using the backbone-on-rails gem with javascript (as opposed to coffeescript) to render views for a model. Everything works fine, but my view code is kind of long so I'd like to refactor things out to use includes/partials. Heres' my code: in my views/model_show.js file AppName.Views.ModelNameShow = Backbone.View.extend({ template: JST['main'], initialize: function() { this.render(); }, render: function() { this.model.fetch({async:false}); $(this.el).html(this.template({ model: this.model

Sails EJS-view after html-pdf usage does not render image

◇◆丶佛笑我妖孽 提交于 2019-12-12 04:28:25
问题 I need to be able to render html views (nothing new there) and to provide the same views as PDF file to the final user. The first case works perfectly on my side : I managed to render a simple html5 document aswell as an image two times (the base64 version + the standard way). Unfortunately, when I try to convert it to a PDF file thanks to html5-to-pdf or html-pdf , the non-base64 version of the <img> tag does not work and is signaled as a missing resource within the PDF File. The code I'm

Error while sending parameters to EJS page from node js

ε祈祈猫儿з 提交于 2019-12-12 04:23:37
问题 I am sending parameters from node js to an EJS page as... router.get("/AdminDatabase", function(req, res) { res.render('Pages/AdminDatabase', { title: 'WebFormsAdmin', role: req.cookies.role }); }); How can I do the same in the below code.. router.get('/CreateSurvey', function(req, res, next) { var Education = QBank.findOne({_id:"id1"}); var Political = QBank.findOne({_id:"id2"}); var resources = { education: Education.exec.bind(Education), political: Political.exec.bind(Political) }; async

Printing mysql data to EJS document with foreign keys

独自空忆成欢 提交于 2019-12-12 03:55:30
问题 Link to github project I'm trying to get answers to quiz questions from mysql and print to a form using EJS templating in node/express application. I can't figure out how to print the correct answers to the corresponding question. I would like the data to look like this in the browser: Question 1 #id2 answer 1 #id6 answer 2 #id7 answer 3 #id8 Question 2 #id3 answer 1 #id9 answer 2 #id10 answer 3 #id11 The data is looking like this: loadQuizes; [ { quizId: 2, quizName: 'Bergskedjor',

Facebook user image not showing on <img> tag

非 Y 不嫁゛ 提交于 2019-12-12 02:32:44
问题 I have a .ejs page with this piece of code <li><% if(userInfo.image=="" || userInfo.image==null || userInfo.image==undefined){ %> <img src="/assets/img/default.png" class="img-responsive pic-bordered" alt="" /><%}else{%> <img src=" <%= userInfo.image%>" class="img-responsive pic-bordered" alt="" /><%}%> </li> The userInfo.image value is "http://graph.facebook.com/xxx728122636xxxx/picture?redirect=true&width=432&height=432" but the image doesn't show. example: https://jsfiddle.net/f6dsp3wd/1/

sailsjs generate dynamic views/ejs files

白昼怎懂夜的黑 提交于 2019-12-12 02:16:36
问题 I'm generating/copying ejs files dynamically and put them in views folder and they work fine in development mode however in production mode it's not reflecting changes until I relaunch sails. How can I make it work in production mode as well? I'm using simple fs create/update file operations to write to ejs file 回答1: Found the solution. Following posts helped me in that: Sailsjs view caching (bug ?) https://github.com/balderdashy/sails/issues/3513 http://expressjs.com/en/api.html The reason