title: In Nodejs, how can i check params in Ejs render
body: <p>I want to display another view if there is :id in Semantic URL</p>
  
  <pre><code>app.get(['/topic', '/topic/:id'], function(req, res){
    id = req.params.id    
    if(id){
      res.render('view',{topics:rows, topic:row[0]}
    }else{
      res.render('view', {topics:rows}
    }
  }
  </code></pre>
  
  <p>and <code>view.ejs</code></p>
  
  <pre><code>for(var i = 0; i &lt; topics.length; i++){
   &lt;li&gt;&lt;%= topics[0].title%&gt;&lt;/li&gt;
  }
  &lt;% if(topic) {%&gt;
    &lt;%= topic.description %&gt;
  &lt;%} else {%&gt;
    &lt;h1&gt;Welcome&lt;/h1&gt;
  &lt;% } %&gt;
  </code></pre>
  
  <p>it did works correctly when i connect to localhost:3000/topic/1</p>
  
  <p>but when i connect to localhost:3000/topic</p>
  
  <p>console said topic is not defined</p>
  
  <p>what is the problem?</p>
  
  <p>When i use </p>
  
  <pre><code>res.render('views', {topics:rows, topic:''}
  </code></pre>
  
  <p>it did works correctly</p>
  
  <p>Do i have to use like this?</p>