Question
· Jul 19, 2016

Zen Mojo - Explicit dispatch javascript function call

I have a Zen Mojo application, developed using Bootstrap plugin and using "Explicit Dispatch" with multiple templates.

I have every template representing an specific area of my application (customer, order, logon, application settings, etc.). 

Each template has specific code,  client side validation and so on related to its areas by using javascript.

So, I would like to know if it is possible, for example, through my order template call a javascript function from another template (e.g.: customer), where I there is functions for document id validation, date of birth validation, etc.?

Thank you.

Discussion (2)0
Log in or sign up to continue

Hi Fabio,

yes, in theory, there is a way how you can load other templates, but I do not encourage this approach as loading a template can be expensive.

It is better to use one of the following two approaches:

1) Generic utility functions should be placed in a javascript file that can be included

2) You can also build a base template that includes your utility functions and let your other template subclass the base template.

The second approach makes sense if it is unlikely that a given template that requires these utility functions will be loaded and you want to save the footprint. Otherwise, I would always stick to option 1.