hogan-express icon indicating copy to clipboard operation
hogan-express copied to clipboard

FIX: lambdas receive the text but don't receive the lctx (variables needed to do useful things)

Open spadkins opened this issue 7 years ago • 1 comments

I declare my lambdas to have two arguments, the enclosed text and the set of options/variables. e.g. See at the bottom for two examples. However, while the "text" is passed ok, the "ctx" is always undefined. In this state, lambdas are much less useful than they could be. I copied the module and made the following change, and it works perfectly for me. May I suggest that the change is made in the sources? (As it is, I am using the modified version of hogan-express.js in my project.)


hogan-express.coffee (line 85) OLD: return lambda(hogan.compile(text).render(lctx)) NEW: return lambda(hogan.compile(text).render(lctx), lctx)


hogan-express.js (line 131) OLD: return lambda(hogan.compile(text).render(lctx)); NEW: return lambda(hogan.compile(text).render(lctx), lctx);


var lambdas = {
    ifLoggedIn: function(text, ctx) {
        var user = null;
        if (ctx && ctx.user) {
            user = ctx.user;
        }
        if (user && user.username !== 'guest') {
            return text;
        }
        else {
            return '';
        }
    },
    ifNotLoggedIn: function(text, ctx) {
        var user = null;
        if (ctx && ctx.user) {
            user = ctx.user;
        }
        if (!(user && user.username !== 'guest')) {
            return text;
        }
        else {
            return '';
        }
    }
};

spadkins avatar Sep 13 '16 23:09 spadkins

@spadkins This module is no longer maintained (as far as I can tell), but I've migrated it here and published it as hogan-xpress and incidentally, this issue is fixed there . . . or should be. If it's not, feel free to open an issue there.

tandrewnichols avatar Jul 18 '17 00:07 tandrewnichols