0

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?

    1 Answer 1

    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' %>" /> 
    Share

      Not the answer you're looking for? Browse other questions tagged or ask your own question.