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

2

16

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.

Testify answered 5/3, 2017 at 14:55 Comment(0)
C
26

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!

Colville answered 5/3, 2017 at 18:29 Comment(2)
Instead we have to use double quote in place of single quote {link: " you link"}Testify
This is how I used it in my app, and it's working fine for me.Colville
D
4

Here is a way it worked for me.

General example:

<a href="somepath/<%= someVariable %>">Read More</a>

Example from my project:

<a href="/post/<%= post.titleTxt %>">
Delighted answered 11/3, 2022 at 14:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.