Skip to content

Add support for generic Mustache JSON widget in EFSA

It's coming up more often lately that we need one-off/simple solutions for applying mustache templates to raw JSON without processing. Rather than rewriting the application of the template to the raw data, we should look into writing a generic method for this that accepts 3 attributes, with at least 2 attributes set to function.

Attribute Function Required
data-static-url Provides a static URL for retrieving JSON to be formatted by the function Yes (if data-url-callback is not set)
data-url-callback Provides the name of a function that takes a DOM element and builds a URL for retrieving dynamic JSON content. Yes (if data-static-url is not set)
data-template-id The ID of the template embedded on the page to use to process JSON into HTML Yes

With a method/listener that implements something like this, we could cover simple mustache templates without a release of EFSA or writing JS and enable faster development.