Enhancing the script repository


The script editor lets you write and execute scripts from the back-office tool, which is also present in the administration and repository views.

It is based on GraalJS syntax.

It can be enhanced with your own customizations.

  1. Enhancing the script repository
    1. Variables
    2. Functions
    3. Tutorials

Enhancing the script repository

If there are pieces of code that you use regularly in your scripts, you are encouraged to enrich your repository so that they are available in all your scripts.

You can enhance the script tool with your own variables, functions and tutorials by adding the WEB-INF/param/scripts file .xml.

The format is as follows; each tag is optional.

<?xml version="1.0" encoding="UTF-8"?>
<binding>
   <variables>...</variables>
   <functions>...</functions>
   <tutorials>...</tutorials>
</binding>

Variables

To define variables, under the variables tag, add a variable tag for each desired variable.

Each variable tag includes :

  • name : Variable name
  • text : Explanatory text
  • script Code corresponding to variable initialization. It is recommended to externalize it via the file attribute, which contains a relative path
  • signature Variable signature
    • type : Type of variable
  • examples with several tags example itself composed of :
    • text: Explanatory text for the example
    • script Content of the example. It is recommended to externalize it via the file attribute, which contains a relative path
<variable>
   <name>Content.selection</name>
   <text type="i18n">PLUGINS_CMS_SCRIPT_VAR_SELECTION</text>
   <script file="js/Content-variables.js"/>
   <signature>
       <type>org.ametys.cms.repository.Content[]</type>
   </signature>
   <examples>
       <example>
           <script file="examples/Content.selection-01.js"/>
       </example>
   </examples>
</variable>

Functions

To define functions, below the functions tag, add a function tag for each desired variable.

Each function tag includes :

  • name : Function name
  • text : Explanatory text
  • script Code corresponding to the function content. It is recommended to externalize it via the file attribute, which contains a relative path
  • signature Function signature
    • type : Type of function return value
    • text : Return value documentation
    • arguments composed of several argument with :
      • name: Argument name
      • type: Type of argument
      • text: Text explaining the argument
      • optional: Boolean indicating whether the argument is optional
  • examples with several tags example itself composed of :
    • text: Explanatory text for the example
    • script Content of the example. It is recommended to externalize it via the file attribute, which contains a relative path
<function>
   <name>Solr.contentQuery</name>
   <text i18n="true">plugin.cms:PLUGINS_CMS_SCRIPT_FCT_SOLR_QUERY_CONTENT</text>
   <signature>
       <type>org.ametys.plugins.repository.AmetysObjectIterable</type>
       <text type="i18n">PLUGINS_CMS_SCRIPT_FCT_SOLR_QUERY_CONTENT_SIGNATURE_RETURN</text>
       <arguments>
           <argument>
               <name>query</name>
               <type>String</type>
               <text type="i18n">PLUGINS_CMS_SCRIPT_FCT_SOLR_QUERY_CONTENT_SIGNATURE_ARG_QUERY</text>
           </argument>
           <argument>
               <name>contentTypes</name>
               <type>String/String[]</type>
               <text type="i18n">PLUGINS_CMS_SCRIPT_FCT_SOLR_QUERY_CONTENT_SIGNATURE_ARG_CONTENT_TYPES</text>
           </argument>
           <argument>
               <name>facets</name>
               <type>Object</type>
               <text type="i18n">PLUGINS_CMS_SCRIPT_FCT_SOLR_QUERY_CONTENT_SIGNATURE_ARG_FACETS</text>
           </argument>
           <argument>
               <name>workspaceName</name>
               <type>String</type>
               <text type="i18n">PLUGINS_CMS_SCRIPT_FCT_SOLR_QUERY_CONTENT_SIGNATURE_ARG_WORKSPACE</text>
           </argument>
       </arguments>
   </signature>
   <examples>
       <example>
           <script file="examples/Solr.contentQuery-01.js"/>
       </example>
   </examples>
</function>

Tutorials

Tutorials are documentation only. Under the tutorials tag, add a tutorial tag for each tutorial you want.

Each tutorial tag includes :

  • name : Label
  • text : Explanatory text
  • examples with several tags example itself composed of :
    • text: Explanatory text for the example
    • script Content of the example. It is recommended to externalize it via the file attribute, which contains a relative path
<tutorial>
   <name type="i18n">PLUGINS_CORE_UI_SCRIPT_TUTO_FIRSTSTEP</name>
   <text type="i18n">PLUGINS_CORE_UI_SCRIPT_TUTO_FIRSTSTEP_DESCRIPTION</text>
   <examples>
       <example>
           <text type="i18n">PLUGINS_CORE_UI_SCRIPT_TUTO_FIRSTSTEP_EXAMPLE_01</text>
           <script file="tutorials/tuto-01.js"/>
       </example>
       <example>
           <text type="i18n">PLUGINS_CORE_UI_SCRIPT_TUTO_FIRSTSTEP_EXAMPLE_02</text>
           <script file="tutorials/tuto-02.js"/>
       </example>
   </examples>
</tutorial>

 

Back to top