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

177
Views
ejs code stored in string wont execute on frontend

I have part of code stored in db as a string. So that would be

var code = "<% if ('undefined' === typeof(store.disable_sharesale_upsellit) || store.disable_sharesale_upsellit == false) { %>

    <% if (typeof(store.settings.shareasale_id) != 'undefined' && '' != store.settings.shareasale_id && typeof(store.settings.allpages_upsellit_snippet_pixel) != 'undefined' && store.settings.allpages_upsellit_snippet_pixel != '') { %>
    <script>
        var shareasale_id = <%- JSON.stringify(store.settings.shareasale_id) %>;
        console.log(shareasale_id);
        console.log('shareasale123');
    </script>
    <% } %>

    <% if (typeof(store.settings.upsellit_id) != 'undefined' && '' != store.settings.upsellit_id && typeof(store.settings.allpages_upsellit_snippet_pixel) != 'undefined' && store.settings.allpages_upsellit_snippet_pixel != '') { %>
    <script type="text/javascript">
      console.log('upsellit');
    </script>
    <% } %>

<% } %>"

Now im passing this variable thru res.view as setting and in the ejs file im trying to pass it like this:

<%- store.settings.code %>

but what im getting is that js console.logs are executed but ejs tags are shown on page as they are in paragraph. Also the console log where ejs tags are present throws error. Not doing the if checkings as it does when the code is written directly in the ejs file. Any hint how to pass ejs code stored as string in the ejs file?

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!