Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 923
Sagar Rana Magar Avatar asked Mar 05 '17 14:03

Sagar Rana Magar


People also ask

How do you make a dynamic HREF in HTML?

getElementById('someDiv'); // create <a> tag var tag = document. createElement(a); // set the href attribute tag. setAttribute('href', exampleHref); // append the node to the parent div. appendChild(tag);

Can I use EJS instead of HTML?

If you want to render a static page then go for an HTML file and if you want to render a dynamic page where your data coming from various sources then you must choose an EJS file. Good for the static web page.


1 Answers

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!

like image 104
zoecarver Avatar answered Sep 18 '22 14:09

zoecarver