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

340
Views
How do I add a button class based on a res.local variable in ejs?

I have buttons on a page. Some will be deactivated based on a res.locals variable. However, I can't figure out how to add a class using ejs. I'm looking to do something like this:

<button class="class1 class2 <% if (res.locals.myVariable === "a") { %> class3 <% } >" />
<button class="class1 class2 <% if (res.locals.myVariable === "b") { %> class4 <% } >" />

The first button would only have class3 if myVariable was set to "a", and the second button would only have class4 if myVariable was set to "b".

How can I do this? Is ejs the way to go or is there a better solution?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can just use your variable name which you defined with res.locals in your app. If you defined res.locals.myVariable = somevalue; then you can simply use myVariable like this:

<button class="class1 class2 <% myVariable === 'a' ? 'class3' : 'class4' %>" />
about 4 years ago · Juan Pablo Isaza Report
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!