Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

299
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda