ejs

is there a way to add CSS/JS later using EJS with nodejs/express

杀马特。学长 韩版系。学妹 提交于 2019-12-20 09:20:43
问题 i'm using the EJS template engine with nodejs/express and i'm wondering if it's possible to add another css or js file in e.g the index.ejs (not the layout.ejs) layout.ejs <!DOCTYPE html> <html> <head> <title><%= title %></title> <link rel='stylesheet' href='/stylesheets/style.css' /> <link rel='stylesheet' href='/stylesheets/smoothness/jquery-ui-1.8.14.custom.css' /> </head> <body> <%- body %> </body> </html> index.ejs <h1><%= title %></h1> <p>Welcome to <%= title %></p> i don't want to add

How do I pass a variable to inline javascript using EJS templating engine?

我与影子孤独终老i 提交于 2019-12-20 05:33:07
问题 I've created a html list of buttons/text from an array called items in an .EJS template. How do I pass the specific item's id (item.id) to the button's function so I can send the right data to my api? Thanks. <!DOCTYPE html> <html lang="en"> <head> <title>Menu</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script> <script type="text/javascript"> function print(id) { $.ajax({ url: "https://www.example.com/api/1/print", type:

Can node presented ejs files use offline bootstrap?

烂漫一生 提交于 2019-12-20 04:27:13
问题 I'm new to node and full stack development and hope I ask this correctly and not carelessly or offensively for your particular level of understanding. My dev environment is Internet connected, production will not be and I want to use bootstrap.css with node. Apache/httpd is not an option in production. Testing bootstrap locally has been challenging, the correct directory for the css file is believed correct. The main directory on CENTOS 7 is myapp, contains app0.js, the node_modules with

Passing Variable with EJS Templating

主宰稳场 提交于 2019-12-19 19:45:12
问题 I am using the Ejs templating engine for my expressjs project and despite passing my objects along to my view blog.ejs file, I am receiving an blogpost not defined error in my ejs file. Error is happening at my <% blogpost.forEach(function(blogpost) { %> line. I figure that is has something to do with how im passing the object and its properties, but I followed guides and it appears correct. routes.js: //blog router.route('/blog') // START POST method .post(function(req, res) { var blogpost =

Nodejs EJS helper functions?

不问归期 提交于 2019-12-18 10:33:23
问题 Is there a way to register helper functions to EJS templates, so that they can be called from any EJS template? So, it should work something like this. app.js ejs.helpers.sayHi = function(name) { return 'Hello ' + name; }); index.ejs <%= sayHi('Bob') %> 回答1: Yes, in Express 3 you can add helpers to app.locals . Ex: app.locals.somevar = "hello world"; app.locals.someHelper = function(name) { return ("hello " + name); } These would be accessible inside your views like this: <% somevar %> <%

How to render multiple .ejs files in nested form in Node.js and Express?

守給你的承諾、 提交于 2019-12-18 03:40:10
问题 How can I render multiple .ejs files in a nested form? So I have the following file: var mysql = require('mysql'); var ejs = require('ejs'); exports.index = function(req, res){ if (req.method=='POST'){ var connection = mysql.createConnection({user:'root', password:'root', database:'testdb'}); var name = req.param('name'); connection.query('select * from table_name where name = ?', name, function(err, rows, fields){ if(err) throw err; res.render('index', { title: 'title', content: res.render(

ejs 'partial is not defined'

▼魔方 西西 提交于 2019-12-17 23:33:41
问题 Okay I have a mostly static homepage but I wanted to have partial views that for navigation, footer ect. I'm using ejs and it looks like this: my controller: home.js // Dependencies var express = require('express'); module.exports = { get: function(req, res) { app.set('view engine', 'ejs'); var model = { layout:'home', }; res.render('home'); } }; My views directory has nav, home and footer all .ejs Then the actual html file stripped of text would look as following. <!DOCTYPE html> <html>

Render ejs file in node.js

谁说我不能喝 提交于 2019-12-17 18:10:13
问题 Hey guys I'm playing with node.js and trying to render an template file. I figured out how to render strings: var http = require('http'); var ejs = require('ejs'); var server = http.createServer(function(req, res){ res.end(ejs.render('Hello World')); }); server.listen(3000); How can I render a template file? 回答1: var templateString = null; var fs = require('fs'); var templateString = fs.readFileSync('template.ejs', 'utf-8'); and then you do your thing: var server = http.createServer(function

How to include external .js file to ejs Node template page

。_饼干妹妹 提交于 2019-12-17 16:58:24
问题 I cannot find a way to include external .js file to Node ejs template. I want to put logic and data into object in external .js file, include that file to index.ejs template and pull data from it. I tried by inserting standard way <script src="sample.js"></script> , and it doesn't work Then I tried ejs specific keyword <% include partials/sample.js %> and this works only for adding partials (ejs code snippets). I inserted .js file into static directory which is defined in executable server.js

Pass variable from Express to Client JavaScript

让人想犯罪 __ 提交于 2019-12-14 02:35:47
问题 Ultimately I'm trying to pass JSON data from the Node server to be used by D3 in the client. Here's my index.js var express = require('express'); var router = express.Router(); var portmix = require('../data/holdings.json'); /* GET individual portfolio page. */ router.get('/portfolio/:portcode', function(req, res) { var porthold = []; for(var i in portmix){ if(portmix[i].PortfolioBaseCode === req.params.portcode){ porthold.push(portmix[i]) }} res.render('index', { pagetype: 'single_portfolio'