I am working on a template and need to be able to keep a list of content IDs that have already been added to the page. This is so that in another area of the page where we add a different variant of the same content type we prevent the same content ID from being added twice.
Thanks for any advice and help you can give.
one way to create a list is use $user.PSOListTool.asList().
With that, what would you do to add items to that list once a variable holding that list was created?
You can use the add() method. See the Java Doc for java.util.list:
There are some other methods, including addAll(). They are described in the JavaDoc page for List.
$foo = $user.PSOListTool.asList("abc")
$foo is now a list with 2 elements: “abc”, “def”
I thought I tried that but maybe I did something wrong. I’ll try again, thank you.
Hi there I have tried following this process to create a list but it doesn’t work?
I have the PSO toll installed but can’t seem to create a list.
I usually use something like…
#set($myarray = )##
…to create an empty array, then call the add() method on it to add elements to it.
That appears to work fine!
Thank you very much that has had me stumped so far!
Just trying this out. If you use this is a Velocity template how do you get it to not render the ‘true’ return value of the .add
method? It looks like there is version of add that won’t do this if you specify the index prior to the element like so:
#set($foo = $user.psoListTools.asList(“abc”))
But I can’t seem to get this to work in a for loop with index provided by $velocityCount - 1 or something along those lines. Any suggestions?
[li]What version of Percussion CM are you using?[/li][li]Do you encounter any error messages?[/li][li]Can you provide a snippet of the code you’re attempting to use?[/li][/ul]