Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

298
Views
EJS Variable Not Displaying

I'm working on a random quote machine. Here's my NODE stuff:

var express = require("express");
var app = express();

app.set("view engine", "ejs");

app.get("/", function(req,res){
    var data = "http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1";
    res.render("home", {data: data});
});

app.listen(process.env.PORT, process.env.IP, function(){
    console.log("SERVER STARTED"); 
});

Here's the EJS stuff...

<h1>HELLO</h1>

<li><%= data.data %></li>

Everything is going fine, except here's the issue...

"data.data" in the EJS brackets, it's just nothing. Nothing there. And I've wracked my brain trying to figure out what's going on, but I can't. Bracket notation didn't work either. Any ideas what's going wrong?

Thanks!

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

When you pass stuff to the renderer, the object you pass in the second parameter becomes a 'global' in the ejs rendered page. So when you set something like below:

res.render("home", { myString: "I like strings" });

...you can access it by referring to the thing inside the passed object:

<li><%=myString%></li>

so your data.data is pointing to nothing.

over 4 years ago · Santiago Trujillo Report

0

I have the same issue and this is my solution. Add .toJSON() after data:

<li><%=data.toJSON().data%></li>
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!