ConditionScriptMacro
Enables you to display or hide certain content depending on the execution result of a certain script.
Example
Let’s say, you don't have data for the table you created using the TableScriptMacro, and your table is displaying the headers only. To avoid this, you can use the ConditionScriptMacro.
1. Writing the code
To create a script, go to ConfluenceAdministration > Add-ons > cPrime Tools, and click SIL Manager.
Click the silprograms folder and then New > New file.
Create a new SIL file and name it, for instance HasDescendants.sil like in the image below.
In the HasDescendants.sil file that you created, write the following script. It hides the table from the page if there's no data for such table.
if (size(argv) < 2) { print("space key and page title are not specified"); return false; } string spaceKey = argv[0]; string pageTitle = argv[1]; number page = getPage(spaceKey, pageTitle); if (page < 0) { print("space'" + spaceKey + "' has no page '" + pageTitle + "'"); return false; } number[] descendants = getPages(page); return size(descendants) > 0;
Click Check and Save.
You can find more information about managing your SIL Scripts on the SIL Manager page.
2. Creating a ConditionScriptMacro
So, you have created a script but before using it, you need to create a ConditionScriptMacro and associate a script with it.
To add a ConditionScriptMacro, go to the necessary Confluence page, click Insert more content, and select Other macros > SIL condition.
In the displayed dialog, fill out the necessary fields:
Enter the script name that you created.
Enter the input - space key and the page name where you want to display the variables.
Select the separator. 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.
Click Save, to see the table is no longer displayed on the page.
Summary
You have created the HasDescendants.sil script and a ConditionScriptMacro that is associated with this script.
Result
Every time you update a page, the macro will hide the table if there is no data for it.