Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

297
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda