My login route is saving user data with a permission_id
key that needs to be checked to determine whether it is greater than 1 or less than 2. Depending on the value of permission_id
, I need to render different HTML content to allow or restrict access to certain content for users.
To achieve this, I have created a helper in my server file:
const hbs = exphbs.create({
// create custom helper
helpers: {
permissionCheck: function(value){
if (value < 2) {
value = true;
} else {
value = false;
}
}
}
});
Now, in my handlebars file, I am trying to implement the helper like this:
{#permissionCheck req.session.permission_id }}
{{else}}
{{/permissionCheck}}
However, I have been facing some challenges in getting the syntax right, as I have attempted {{#if (permissionCheck req.session.permission_id)}} without success.
I am struggling to create a helper that behaves like a conditional statement to properly check the permission_id
variable and display the relevant content accordingly.