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

337
Vistas
How to display a STRING of ejs code saved in a variable on another ejs template?

My objective is to have a page on which I would like to display some information via ejs in a specified div. There would be some buttons to change the way and/or the displayed information.

I've already created the button to display a dummy text. Now I would like to display some different template already stored as a string in my DB.

So I have this first ejs file, from where the user should be able to select another part of displayed code via some button. The buttons use a JS script to display the code with an .append(). I use

<%- JSON.stringify(stringOfCode)%>

to display my template. My problem is that the code is displayed within some quotation marks and that the ejs inside the stringOfCode is not working:

"
TEST TEMPLATE
Email Address : <%= user.email %>
First Name : <%= user.firstName %>
Last Name : <%= user.lastName %>
"

How can I solve this ? Or is there a better suited solution for what I want to do ?

EDIT

In my search of a solution, I've tried this : I put the content of stringOfCode into a new ejs file called test0 In my script, I used this:

     wrapper.append('<div class="container canvas" id="toCan"> Test 1  <%- include('test0'); %>   </div>');

the result is that my button stopped working. I suppose this cause some kind of conflict when rendering the test0. Simply putting <%- include('test0'); %> works fine on its own, but that not what I'm aiming for

about 4 years ago · Juan Pablo Isaza
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