Discussions

Ask a Question
Back to All

Check if date current in helper.

Hi guys,

Struggling to write a custom helper, inside of my template.hbs I have created checkActive to see if the moment from the context given is past a certain point, however attempting to use the following code in a block will throw an error.

<script>

    Handlebars.registerHelper('checkActive', function (context) {
        if (window.moment && context && moment(context).isValid()) {
            return moment(context) =< moment();
        } else {
            return context;   //  moment plugin is not available, context does not have a truthy value, or context is not a valid date
        }
    });

</script>
<div class="text">Clos{{#checkActive Dates.EndDate}}ed{{else}}ing{{/if}}</div>
Failed to render Handlebar template Portals/0/OpenContent/Templates/.../template.hbs
Value cannot be null. 
Parameter name: test