I’d like to populate the url from an item which holds a non determined amount of file names as a csv string, like this:
photo1.jpg,photo2.jpg,photo3.jpg,...
How can I do that? I also need to add a prefix. For a better understanding I added the code which does not work and omitted the caption attribute. Also a forEach expression does not work,too.
should give you the first value in the list. Change the number at the end to go to 2, 3, 4, etc. To make the widget generic and configurable, you could make `‘ItemName’ be a property.
yaml is a human readable short hand for JSON. The - syntax are array elements. So in reality actionsPhotos is getting set to a JSON array of objects with a caption key and a url key. So:
This gives you a couple of different options. Do you have control over the original list item? By that I mean are you populating this from a rule or external script file? If that’s the case then instead of sending just the list of photos, create the full array object in the rule/script where you have the full power of JS or some other language available to you. If you set the item state to the stringified object then you can just parse that string in the widget.
actionPhotos: =JSON.parse(@@vKlingelFilenames)
If you don’t have that access to the item state then you can probably create the array from the string using split and then use map and an arrow function to map each element in the new array to an object with the correct keys. Of the top of my head I’d say something like this:
Yes since 3.4 arrow functions are supported so you can map arrays like:
="foo,bar,baz".split(",").map(i => "prefix-" + i)
which will give you:
[ "prefix-foo", "prefix-bar", "prefix-baz" ]
That’s enough for the photo browser, if you don’t need captions, you can just feed it an array of URLs, but you can use @JustinG’s answer to build a more elaborated array.
As my expression is getting more and more complex I am creating the whole json string in a seperate rule, as you suggested. This works fine s far. I am struggeling just with the following:
In the epression of the widget I was able to use e.g. split inside the arrow function
I assume that you’re trying to strip the file extension of the file name in the list with e.split(".").get(0). An array conversion is probably overkill. Maybe just try substring instead: e.substring(0,e.indexOf("."))