ScriptMacro





Enables you to display the standard variables for the predefined page.

Example

In this example we'll show you how to display the standard variables of your page.

1. Writing the code

  1. To create a script, go to Confluence Administration > Add-ons > cPrime Tools, and click SIL Manager.

  2. Create a new SIL file. To do that, click the silprograms folder and then New > New file. 

  3. Name your new file, for example PageStandardFields.sil like in the image below. 





  4. In the PageStandardFields.sil file that you created, write the following code. It represents how the ScriptMacro uses the standard variables. The script takes the page title, ensures that the page actually exists, and returns basic standard variables.

    if (size(argv) < 2) { return "space key and page title are not specified"; } string spaceKey = argv[0]; string pageTitle = argv[1]; number page = getPage(spaceKey, pageTitle); if (page < 0) { return "space '" + spaceKey + "' has no page '" + pageTitle + "'"; } return "id: " + %page%.id, "parent: " + %page%.parent, "title: " + %page%.title, "space: " + %page%.space, "author: " + %page%.author, "version: " + %page%.version, "content: " + %page%.content, "attachments: " + %page%.attachments, "created: " + %page%.created, "updated: " + %page%.updated, "watchers: " + %page%.watchers, "labels: " + %page%.labels, "tinyLink: " + %page%.tinyLink;
  5. Click Check and Save.

You can find more information about managing your SIL Scripts on the SIL Manager page.

2. Creating a ScriptMacro

So, you created a script, but before you can use it, you need to create a ScriptMacro and associate a script with it.

  1. To add a ScriptMacro, go to the necessary Confluence page, click Insert more content, and select Other macros > SIL script.




  2. In the displayed dialog, fill out the necessary fields:

    1. Enter the name of the script that you created. In our case it's PageStandardFields.sil.

    2. Enter the input - space key and the page name where you want to display the variables. In our case we used comma as a separator, and you can define another symbol. For instance, in cases where a page contains commas in the name, you might want to use period as a separator.

    3. Define the separator symbol.

    4. Select the data output - possible options are: list, numbered list, table, transposed table.





  3. Click Save to create a ScriptMacro.


That's it. You have created PageStandardFields.sil script and a ScriptMacro that is associated with this script.

Result

Every time you update a page, the macro will take the page title, ensure that the page actually exists, and return basic standard variables.

See also