Child pages
  • Adding New Scripting Variables
Skip to end of metadata
Go to start of metadata

As of version 2.0.14 of Sling Scripting Core, Sling Scripting allows bundles to contribute objects to the variables available to scripts by exposing OSGi services.

This can be done by implementing either java.util.Map or Implement if you need access to the current script variables.

In either case, implementations are able to add one or more name/value pairs to the javax.script.Bindings object, but they cannot overwrite or remove any of the default scripting variables (defined here: Scripting Variables). These custom bindings can be configured to apply to any scripting language or a specific scripting language.

An example of the binding of a custom object using java.util.Map can be found in the extensions.groovy bundle (source):

In this example, the jsonBuilder key is bound to an instance of JSONGroovyBuilder only for Groovy scripts.

An example of the binding of a custom object using can be found in the jcr.resource bundle (source):

  • No labels

1 Comment

  1. Justin Edelson Excellent wiki page!
    The link to is no longer valid, I believe that class was replaced with this one:

    Also, the class you referenced was moved to contrib, new link here