I've developed an script in SiteArchitect to monitoring purposes that lists all projects in the server.
My approach was to loop through projects and add them to an array:
List<String> projects = new ArrayList<String>();
Then in a loop:
And in the end I return the result:
But what I get when I call the script inside CMS_RENDER tags is the array converted to a string, not the structured data.
I'd like to pass multiple results from the script inside an structured data: array, object...
Is this possible for script results?
$CMS_RENDER$ will directly render the result into the output, you cannot use the renderscript's result as a variable in the template.
But there is a kind of workaround: Just provide some empty container as parameter to the script. In your case an empty list seems a good choice, empty sets or maps can also be used:
In the script, you then have access to the variable "resultContainer" (or whatever you name it) and add the information to it:
To avoid any output by the script itself, you should also add
at the end because otherwise the value of the last expression in the script might get output.
Then, "back" in the template (=after the CMS_RENDER call), the variable "set_result" has been populated by the script and you could for example iterate over it:
You can - of course - also use something simpler, the for loop was just for clarification. It's important that the "container" is defined in the template so that you can access it from there after the script has put some values into it. And, by the way, you could also out other objects there, not only strings.
do you need further help or did Michael's reply already help you? If so, it would be great if you marked his reply as "correct answer" so that other community users find the solution easily. If you have already found a solution by yourself, it would be very kind of you, if you posted it here.