If I understand you correctly, current url
is one term and not two distinct terms (current
and url
) and that you want to pass the url
that is being requested. If so, you can pass that data to your template by just adding it in the optional second parameter to res.render
method and it will be accessible by your helper function getQuantityValueFromURL
like so:
// route.js
router.get('/path/here', (req, res) => {
res.render('your_view', {
data: someData,
currentUrl: req.originalUrl
});
});
// your_view.hbs
{{getQuantityValueFromURL currentUrl}}
However the information your helper is extracting is already accessible in Express in one of the many properties of the req object. You don't need a helper function.
Example 1 (Route Params) if user has requested page https://www.yourshop/path/here/55
:
// route.js
router.get('/path/here/:quantity', (req, res) => {
res.render('your_view', {
data: someData,
quantity: req.params.quantity // (quantity = 55)
});
});
// your_view.hbs
{{ quantity }}
Example 2 (Query Params) if user has requested page https://www.yourshop/path/here?quantity=88
:
// route.js
router.get('/path/here', (req, res) => {
res.render('your_view', {
data: someData,
quantity: req.query.quantity // (quantity = 88)
});
});
// your_view.hbs
{{ quantity }}