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

335
Views
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
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!