Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Can I use dynamicHelpers (expressjs) with extend parameters?

Can I use dynamicHelpers (expressjs) with extend parameters?

Problem

(How) can I use dynamicHelpers with Extend Parameters like this?

app.dynamicHelpers({
    getImageUrl: function (req, res, imageName) {
        return "http://" + req.headers.host + app.set("imageUrl")+"/" + imageName;
    }
});

how can I call this from my template engine?

Problem courtesy of: Rheinprinz

Solution

You return a function from your function:

app.dynamicHelpers({
    getImageUrl: function (req, res) {
        return function(imageName) {
            return "http://" + req.headers.host + app.set("imageUrl") + "/" + imageName;
        }
    }
});

In your template, you use getImageUrl("some image.jpg").

Solution courtesy of: Linus Gustav Larsson Thiel

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Can I use dynamicHelpers (expressjs) with extend parameters?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×