Hi,
thanks for reaching out.
Sure there is a way to solve this, the problem here is that you currently don't have an array of strings you access.
So what you need to do is to create an array and add the $id into it. In Velocity adding a value to an array returns a boolean string and outputs it in the site which you probably don't want to have.
To suppress that behaviour you can create a dummy variable (I call that always $swallow) so that there is no output.
here is the adapted code of yours: