Anyone used an HTML templating engine (e.g. Mustac...
# suitescript
e
Anyone used an HTML templating engine (e.g. Mustache) within SS2.0? Any suggestions/recommendations?
๐Ÿ‘ 1
u
Handlebars should be good with SS 2
c
you can def use handlebars
i typically just make a placeholder text and do a replace and that has worked well for me without any libraries
s
I have used
_.template
because I generally always have lodash available already.
e
hm I was not aware of
_.template
s
it seems to work well for the sort of use cases that have come up in NetSuite work. Nice that it lets you run arbitrary JS as well.
m
Why not freemarker? Already included in the API
1000 1
e
Because you must associate an Advanced Template to a Custom Record or a Saved Search, and this is neither of those things.
m
You don't, you can pass in a template string and render back to a string
Copy code
require(['N/render'], function(render) {
  var data = {
   firstName: "Michoel",
   lastName: "Chaikin"
  }

  var renderer = render.create();

  renderer.templateContent = "Hello ${data.firstName} ${data.lastName}";

  renderer.addCustomDataSource({
    format: render.DataSource.OBJECT,
    alias: "data",
    data: data
  });

  var result = renderer.renderAsString();

  log.debug('result', result); 
});
e
^ This is what I started doing last night after coming to my senses
s
I'm not the biggest fan of FreeMarker and I like the ability to use native JS in my templates if needed. I didn't think FreeMarker can even do that?
e
I'm not a big fan of it, but I do tend towards native functionality as often as possible. I don't need the ability to run arbitrary JS in this particular template so FM should suffice
Plus if my client needs to modify this template later, they have folks who already know FM from elsewhere in NS. No need to throw something new at them
๐Ÿ‘ 1