ejs

Getting the url parameters in an ejs template

二次信任 提交于 2019-12-03 11:56:42
问题 I am trying to create an ejs conditional based on a URL parameter, for example, if the test parameter exists at localhost:3000/page?test, then show a div, else dont show it. My ejs template looks something like: <% include header %> <div class="row"> <%if (title !== "homepage") {%> <%= title %> <div> <% include nav %> </div> <%}%> <div> </div> </div> <% include footer %> Is there a way to access the URL parameters directly from the ejs file? For example, the <%= title %> works fine, is there

Node.js - EJS example

我的梦境 提交于 2019-12-03 11:47:11
问题 I am trying to use Embedded Javascript renderer for node. I installed it using npm, as given here: https://github.com/visionmedia/ejs And I have the following code, but it does not seem to work: var connect = require('connect'), ejs = require('ejs'); var server = connect.createServer( connect.bodyDecoder(), connect.methodOverride(), connect.staticProvider(__dirname + '/public'), function(req,res) { ejs.render('hi'); } ); server.listen(9000); Any help greatly appreciated. 回答1: You need to send

Datetime formatting / customization in ejs

 ̄綄美尐妖づ 提交于 2019-12-03 11:14:10
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? 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> You don't need moment js, you can simply use this <%= new Date().getFullYear();%> Post is old but in case anyone runs into the issue. You can eliminate installing moment and write one little line of

Using interpolation within Node.js EJS includes

蓝咒 提交于 2019-12-03 10:29:28
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' + contents %> where the trailing "contents" is the local variable which contains the relative path to the body

how do i get eclipse to interpret .ejs files as .html?

风流意气都作罢 提交于 2019-12-03 10:16:22
i recently started on a node project and two of the modules i'm using is express and EJS. but default i usually use eclipse as my IDE, it works well for java and decent for html and javascript. but one problem i'm having is that for .ejs files i get no markup color coding, or any form of code completion. it's basically just a plain file. does anyone know how i can get eclipse to interpret .ejs files as .html files? i figure it's pretty similar except for the occasional embed tags. or a recommendation for an IDE more well suited to node.js/html/ejs development. thanks! rlegendi For a specific

Refresh section of a page using EJS and Express

旧时模样 提交于 2019-12-03 10:16:09
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: 'Independent cleaner', nav: nav, houses: houses, roomsForHouse: rooms }); }); return router; }; The first

Pass variable to EJS include

北城以北 提交于 2019-12-03 09:40:47
I have a global header used in a couple of places and I was trying to define its location in a variable that could be passed when rendering a template. Something like: var headerLocation = 'some/location/header.ejs'; res.render( viewDir + '/index', { header: headerLocation } ); And in a template file: <% include header %> header being the value passed in with the render. It doesn't seem to be possible but maybe I missed something so thought I'd ask here. EDIT: This is mentioned in comments on answers below but to summarize, this is now available in version 2 of EJS. See here: https://github

Include HTML blocks Using node.js

匆匆过客 提交于 2019-12-03 09:19:46
问题 This is what I want but probably can't have: Using node.js and express and maybe ejs, I would like to, while writing a regular HTML file in my client dir, server-side-include a template block of HTML. It would be cool also if I could pass variables into the include from the HTML document. Sooo something like: <!doctype html> <html> <head> <%include head, ({title: "Main Page"}) %> </head> <body> <% include header, ({pageName: "Home", color: "red"}) %> ... <<% include footer%>> </body> </html>

Embedding an ejs template inside of an erb template

戏子无情 提交于 2019-12-03 09:06:22
I'm building a javascript-heavy rails 3 app. It uses underscore.js, which has a very elegant templating mechanism built on top of ejs ( http://embeddedjs.com/ ). The problem: embeddedjs borrows heavily from the erb syntax, so including ejs templates in an erb template causes rendering problems with the view. Is there a way to include "non-erb" sections in an erb file? This would let me define ejs templates inside erb files. Right now I'm using a hack where I have a helper that reads the raw contents of a file containing ejs templates, and outputting that as a raw string in the erb template. I

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

时光总嘲笑我的痴心妄想 提交于 2019-12-03 06:48:27
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 Error: Failed to lookup view "error" in views directory Thing is, many of these dependencies are