Suitescript 1.0 & handlebars js

460 Views Asked by At

I'm starting to review some requirements for processing a few HTML templates from within a suitelet using suitescript 1.0

I haven't been able to find any information on handlebars JS from within netsuite but I'm curious as to whether there is any requirements to configuring a suitelet that does the server side generation as I would prefer to use it compared to using the client side implementation

If anyone can share anything useful on how to get a suitelet prepared to make use of handlebars that would be greatly appreciated

1

There are 1 best solutions below

1
On BEST ANSWER

Below is a sample from one of the Suitelets I use handlebars in. You setup the suitelet like any other by creating a form object and a html field to hold the rendered handlebar template.

        var screenTitle = 'Form Title';
        var form = nlapiCreateForm(screenTitle);
        var pageTemplate = nlapiLoadFile('SuiteBundles/Bundle '+sitBundleId+'/src/sit_html_templates/template.html').getValue();
        var hbTemplate = Handlebars.compile(pageTemplate);
        Handlebars.registerHelper('if_eq',function(a,b,opts) { if(a == b) { return opts.fn(this); } else { return opts.inverse(this); } });
        Handlebars.registerHelper('json', function(context) { return JSON.stringify(context); });
        var data = {
                "account_id":nlapiGetContext().getCompany(),
                "bundle_id":sitBundleId,
                "other_data":{}
        };
        var htmlValue = hbTemplate(data);
        var templateField = form.addField('template_section','inlinehtml','',null,'main_group');
        templateField.setDefaultValue(htmlValue);
        response.writePage(form);

Thats the basics. Of course the Handlebar library must be added to the library sublist on the NetSuite Suitelet record.