ejs

Passing variable from ejs to js script

故事扮演 提交于 2019-12-25 02:44:29
问题 I am trying to pass a variable from ejs to JavaScript function but keep getting undefined in output. Here is the code. It is supposed to render a table with file names and clicking on each file name should later redirect to a page which would render the file in the browser but I can't proceed without passing the parameter to URL. <% if (files.length > 0) {%> <table class="table table-hovered"> <thead class="thead-light"> <tr> <th scope="col">No</th> <th scope="col">File</th> <% files.forEach(

How to fix a race condition in Node.js/Express. Where my console will update correctly but my webpage doesn't update

你离开我真会死。 提交于 2019-12-25 01:44:07
问题 I am trying to build a simple webpage based on a couple API's. The issue i am running into is that some of my API's aren't finished getting their data before my page is loaded. Currently my code looks like the following: app.use(express.static('public')); app.use(bodyParser.urlencoded({ extended: true })); app.set('view engine', 'ejs') app.get('/', function (req, res) { res.render('index', {weather: null, headlocation: null, lat: null, long: null, imgLinks: null, WebLinks: null, imgLinksFl:

How to render postgresql results in ejs using node pg?

て烟熏妆下的殇ゞ 提交于 2019-12-25 01:12:19
问题 I'm new to node/express/postgres and trying to build a simple todo application. I'm trying to render a view using an ejs file, but instead of displaying the query results, the page is displaying the query itself: (request, response) => { pool.query('SELECT * FROM items ORDER BY id ASC', (error, results) => { if (error) { throw error } response.status(200).json(results.rows) }) } I'm generating the queries in a queries.js file: const Pool = require('pg').Pool const pool = new Pool({ user: '*',

CSS issues with html-pdf

泪湿孤枕 提交于 2019-12-24 22:53:52
问题 I want to use html-pdf to save a quote made with sails , .ejs , and angular into a pdf to send it to the customer. An .ejs file (view folder) and its assign .js controller (assets folder) allows the user to create the quote, select the customer, add products, and finally calculate the total of the quote. All the data are bound with angular. I use bootstrap.min.css and importer.css files for my CSS and mostly the Bootstrap grid for my display. When to quote is ready, I have a 'save as PDF'

Render EJS - Node JS

梦想与她 提交于 2019-12-24 21:14:12
问题 I would like to update my view after an ajax call, rendering compiled ejs from the server. These two previous questions seem to achieve this but I cannot update my view Can't Render EJS Template on Client How to generate content on ejs with jquery after ajax call to express server So from what I understand I should compile my ejs file (partial) on the server. fixtures.ejs <% fixtures.forEach((fixture) => { %> <h2><%= fixture.home_team %> vs <%= fixture.away_team %></h2> <% }) %> index.js app

How to array of objects in template ejs?

℡╲_俬逩灬. 提交于 2019-12-24 03:36:15
问题 I have a results variable that is an array of objects. I carry the results variable from my javascript file to my main route file. I am trying to render my page to display lists of each object in my template ejs file. I am able to list everything fine, but the lists are coming out as [object object] instead of the actual words that are in the objects. How do I get this to display as strings in my template file? This is my route file: app.get('/announcement', function(req,res){ var

Serve static content and views from same directory?

冷暖自知 提交于 2019-12-23 19:12:26
问题 Is it possible to serve static content and views from the same directory? I found a partial solution below: //Enable Express static content serving: app.use(express.static(__dirname + '/html')); //Static path is folder called html //Also enable EJS template engine: app.engine('.html', require('ejs').__express); app.set('views', __dirname + '/html'); //Set views path to that same html folder app.set('view engine', 'html'); //Instead of .ejs, look for .html extension //Start server app.listen

Rendering layout with ejs

邮差的信 提交于 2019-12-23 05:17:33
问题 I can't render layout with ejs, express: app.configure(function () { app.use(express.static(__dirname + '/public')); app.use(express.basicAuth('username', 'password')); app.set('views', __dirname + '/views'); app.set('view engine', 'ejs'); }); layout.ejs is in /views folder. I render /views/home/index.ejs but it is NOT in layout: res.render('home/index'); layout.ejs: <html> <head> <title></title> <script type="text/javascript" src="/content/scripts/jquery-1.6.2.min.js"></script> <script type=

How to use an ejs variable inside a react render function?

試著忘記壹切 提交于 2019-12-22 11:33:56
问题 I'm passing a variable abcd to my index.ejs which in turn calls a react js file to render the index.ejs page. I've been able to access <%= abcd %> inside index.ejs but not inside the render function of react. Can you help me out? Thanks 回答1: I faced the same problem but with a index.html file, filled by a React component, and resolved it like this: In index.html <script> window.abcd = '<%- abcd %>'; </script> In your react component render: function(){ return( <div> <p> {window.abcd} </p> <

How to execute js with Jade?

安稳与你 提交于 2019-12-22 09:56:52
问题 i was wondering how to execute js before rendering? This fails -#{somejs} // Outputs just the js-code p #{somejs()} // Executes the js-code, but doenst render the html // In EJS I just write. But how can i do this with node? <%- somejs() %> // I try to use express-messasges (https://github.com/visionmedia/express-messages) with Jade instead of ejs 回答1: The following both work for me: - var test = Math.sqrt(16); div #{test} or div #{Math.sqrt(25)} If possible, would you please post your somejs