list¶
Flamingo IDE introduces the list keyword to make working with variable collections easier. It can have true or false values. The default value is false. Below you can see how the list keyword works with both these values.
false
This is the default value. If the list keyword is set to false , you get a string with all found values. See the example below demonstrating such situation.
Code on the desktop site page:
<html>
<body>
<img src="image1.jpg" />
<img src="image2.jpg" />
<img src="image3.jpg" />
</body>
</html>
Code in the parameters collection, where the list keyword is set to false:
image: {
xpath: '//img',
get: '@src'
}
When you use the image parameter in the template/snippet, string “image1.jpgimage2.jpgimage3.jpg” will be returned.
true
In case you set the list keyword to true, you will get an array of all found values and you can use cycles to work with them. See the example below demonstrating such situation.
Code on the desktop site page:
<html>
<body>
<img src="image1.jpg" />
<img src="image2.jpg" />
<img src="image3.jpg" />
</body>
</html>
Code in the parameters collection, where the list keyword is set to true:
imageList: {
xpath: '//img',
get: '@src',
list: true
}
When you use the imageList parameter in the template/snippet, array [‘image1.jpg’, ‘image2.jpg’, ‘image3.jpg’] will be returned.
Now you can use the FOREACH statement to work with this array:
<!--{foreach $.imageList as item }-->
<img src="<!--{= item }-->">
<!--{/foreach}-->
In the result three images available on the desktop site page will be returned.
Note
If you want to check existence of some element on the desktop page with the help of a cycle and the list keyword is set to true , checking won’t be performed correctly, because an empty array is returned. To avoid this, you should define the length of your array, for example:
<!--{= $.imageList.length }-->