We have around 20 separate design templates for our documents (which will grow to at least 60 different templates). In the past we had this in 1 big template file which had the advantage of being able to share everything between the different documents, including the control scripts (that is used, among other things, to create global javascript functions that can be called from other scripts). The problem with having everything in 1 big template is that it becomes too big to be managed by PlanetPress as there are limitations at what the system can handle performance wise and thus we decided to split everything up again.
Unfortunately that means that any changes that are global changes will need to be made to all templates which is a lot of work.
It would be great to have the ability to have control scripts that can be loaded from an external location so that any change to the script is immediately available to all design templates.
How are we doing on the subject?
Now that handlebars have been integrated in connect it would be awesome to have a collection of reusable handlebars in a network (or local share).
For our implementation I have used the suggestion that was given by Erik:
eval(loadtext("http://localhost:1880/test.js"))
Or from the file system like this:
eval(loadtext("C:/workspace/test.js"))
There is a security issue with using this as it will just execute everything that is given so if someone can modify the external scripts then you will get a remote execution attack. As we control the chain from beginning to end and also the server the risk for us is manageable.
For us maintainability, with the amount of templates that we have, is more important.
All our templates also have a control script that holds a Javascript array with the configuration information I can now also configure each template without opening the designer.
And of course our global scripts can also be updated externally.
It would be nice to have a more uniform solution but the remote execution security risk will still remain because the process can never know if a script is safe to execute or not.
@Maxiride we are planning for remote Handlebars as an option for the template resources. At this stage this could be achieved using the following User script.
let productTpl = loadtext("http://localhost:1880/snippets/somehbstemplate.hbs")
let product = Handlebars.render(productTpl)
results.after(product)
You won’t find {{+ in the documentation of the official Handlebars library. What we have in Connect is a custom implementation.
We introduced {{+ as an alternative to {{> because > is a reserved character in HTML. If you add HBS expressions in section content (rather than a snippet) we recommend that you use {{+ rather than {{> for a partial reference.
For now I have solved it by configuring a placeholder in a config file and linking that to a remove handlebars script. A script in every template reads this information and replaces the placeholder(s) with the actual script content.
The reason for this is that I am not a big fan of having a full path in template files all over the place.
Now I only have full paths in my configuration and only there so that is easier to manage.