ejs

EJS include file relative to project root

血红的双手。 提交于 2019-12-04 04:49:32
I am using Express and EJS to build a site and I have a directory structure somthing like: +--www/ | +--partials/ | | | +--header.ejs | +--(a bunch of ejs files) | +--guide | | | +--index.html | +--(other files) | +--index.html In both of the index.html files shown in my example, the <% include ... %> command would be different, even if referencing the same included file. Also if I were to say include header.ejs and then header.ejs has an include for another partial, the whole system breaks down because they are all looking for files in different locations. To make management easier, I'm

How to use multiple layout within a SailsJS app?

隐身守侯 提交于 2019-12-04 04:30:19
My Sails.js application have separate frontend and admin layout. My view engine is ejs . How do I use separate layouts for frontend and admin site? Can I use specific layout for each action? From Sails.js Documentation : At least in EJS, instead of indicating your custom layout with the layout local, you must use _layoutFile: res.view({ _layoutFile: 'relativePathToYourCustomLayoutFromTheTargetView.ejs' }); The path to the layout you're wanting to use should be specified relative to the view you're rendering. So if you're in the create action of the UserController, rendering a view (views/user

JSON from EJS to JSON object in JS

不想你离开。 提交于 2019-12-04 04:19:13
I am using EJS with Node.JS, and am passing a JSON object into it, but need to have access to it as a usable object in the page. I am getting the unexpected token o error from this: var initData=JSON.parse(<%-JSON.stringify(list)%>); I cant figure out whats wrong here. This is what it looks like in the file when rendered: var initData=JSON.parse([{"title":"South Hills Health System - University Health Center","adr":"200 Lothrop St,15213","coords":"40.441875,-79.960813","images":[],"tags":[],"_id":"51c0e9798384f40000000017"},{"title":"Bombay Food Market","adr":"4605 Centre Avenue, Pittsburgh,

node下使用express框架,ejs模板引擎

泪湿孤枕 提交于 2019-12-04 04:03:25
ubuntu下安装 node npm相关 apt-get update apt-get install -y python-software-properties software-properties-common add-apt-repository ppa:chris-lea/node.js apt-get update apt-get install nodejs 命令执行完之后,Node.js就安装好了,一旦Node.js 有新版本发布,直接升级即可,无需从头编译安装; 这样, node 就直接可以输入命令使用了。在Ubuntu环境下,node位于 /usr/bin 路径下; 执行 ,检查安装是否正确 node -v npm -v 执行 安装web框架 npm install -d express -g代表安装到NODE_PATH的lib里面,而-d代表把相依性套件也一起安装。如果沒有-g的话会安装目前所在的目录(会建立一个node_modules的文件夹)。 来源: oschina 链接: https://my.oschina.net/u/859156/blog/417631

How can I turn an EJS template into a string?

≯℡__Kan透↙ 提交于 2019-12-04 03:48:46
I want to pass my variables into that template, let it render, and then get the resulting HTML as a string. How can I do that in Express? Depending on the ejs version the following should work. var ejs = require('ejs'), fs = require('fs'), file = fs.readFileSync(__dirname + '/template.ejs', 'ascii'), rendered = ejs.render(file, { locals: { items:[1,2,3] } }); console.log(rendered); You may need to install ejs if it isn't already installed. cd;npm install ejs You don't need to use fs. This is built into EJS (not sure if it was at the time previous answer was posted). It returns a Promise

How to render a view into a string in SailsJS?

让人想犯罪 __ 提交于 2019-12-04 03:42:01
问题 In one controller I want to render a certain view with a certain layout to send an email with the resulting string, but I obviously do not need to show the result to the user. Is there a way to use the EJS engine that I'm using to render views to achieve this? Here's my a bit simplified controller action: setEmail: function(req, res) { var update = { activationToken: _getToken(), email: req.param('email') }; Profile.update(res.locals.profile.id, update).then(function(profile) { res.redirect

Nodejs/Express: Error: Failed to lookup view “error” in views directory

巧了我就是萌 提交于 2019-12-03 17:50:19
问题 I switched my nodejs template engine over to ejs (from jade). When I run my app.js with my ejs template, I receive a series of "Failed to lookup view 'error' in views" logs. Some of which include: GET /css/bootstrap.min.css 500 12.588 ms - 1390 Error: Failed to lookup view "error" in views directory ... GET /css/clean-blog.min.css Error: Failed to lookup view "error" in views directory ... GET /js/bootstrap.min.js Error: Failed to lookup view "error" in views directory ... GET /js/jquery.js

ejs how to iterate object

陌路散爱 提交于 2019-12-03 17:25:05
问题 I have a simple object literal which is address as shown here address: { country: String, state: String, city: String, zip: String, street: String } and its inside an object which i'm passing with express.js render function. in my template page i'm trying to for loop inside this object as shown: <% for (var prop in artist.address ) { %> <%- artist.address[prop] %> <% } %> which output the data but includes the ejs functions as well like so: function () { return this.get(path); } function () {

How to Debug EJS code in Chrome/Safari

浪子不回头ぞ 提交于 2019-12-03 13:49:23
I am using EJS templates with CanJS and are looking for a way to debug my EJS code. Currently firebug can show me the syntax errors in EJS but in other browsers, I am not able to see anything.I need to go through my EJS file very carefully to solve the errors. I searched on web and found out about ejs_fulljslint https://code.google.com/p/embeddedjavascript/ , but not able to run this properly. I included the script into my HTML file but still wasn't getting any console errors. I am not able to find a demo of debugging on web. Can anyone tell me how to debug my EJS code. If you can provide me

How to: Use ejs without express

 ̄綄美尐妖づ 提交于 2019-12-03 13:04:35
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_data = "test data"; response.end(ejs.render("./views/home.html",test_data)); } exports.index = index;