Search code examples
node.jsapiexpressserverejs

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


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.


Solution

  • 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!