lundi 22 juin 2020

How can i use the value received in this object to create an if statement that executes if the object value matches a string?

This is the app.js snippet:

app.get("/cars", function(req, res){

  res.render("cars", {
      posts: posts,
      topic: req.body.postTopic
  });
});

The key topic has the value that is chosen from a list. I want to use that value to create an if statement in my ejs file. This is what i have in the ejs file.

<%if (topic === "Cars") { %>
    <% posts.forEach(function(post){ %>
    <div class="row">
      <div class="col-lg-8">
        <div class="left-pic">
          <a href="#"><img class="blog-pic" src="https://is2-ssl.mzstatic.com/image/thumb/OopNiLAItfTRfbKBh1IP4Q/1200x630.jpg" align="left"></a>
        </div>
        <a href="#">
          <p class="blog-title"><%= post.title%></p>
        </a>
        <div class="author">
          <span class="author-topic"><a class="author-name" href="">Willie Rose</a> | <a class="topic-name" href=""><%= post.topic%></a></span>
        </div>
      </div>
    </div>
    <% }); %>
<%  } %>

I only what this function to work if the topic value matches the string inside the if statement. I am new to this and just trying to create something of my own. I would really appreciate the help.

Aucun commentaire:

Enregistrer un commentaire