I want to make href tag dynamic and value will be populated and i have ejs template

Sagar Rana Magar picture Sagar Rana Magar · Mar 5, 2017 · Viewed 18.4k times · Source

Sample code snippet:

index.ejs

<p><a href="<%=link%>" class="btn btn-primary" role="button">Download</a></p>  

app.js

var express = require('express'); var router = express.Router(); 

router.get('/', function(req, res, next) {
    res.render('index', {link:'http://download1588.mediafireuserdownload.com/**c5cq****rb2a/***.jpg'});
}); 

how to get this link as href tag value so that i can download from this link.

Answer

zoecarver picture zoecarver · Mar 5, 2017

Here is the way you would do that with ejs:

index.ejs

<p><a href="<%= link %>" class="btn btn-primary" role="button">Download</a></p>

app.js

res.render('index.ejs', { link: "<your link here>" });

Hope this helps!