In the video blow, I am playing around with web widgets, in order to show you how the [for-each] statement in pf.lambda works. The [for-each] statement allows you to iterate over a node-set, and execute a piece of code, once for each expression result. Consider the following code;
_data foo1:bar1 foo2:bar2 for-each:@/-/*?value // do stuff with @/./*/__dp?value
The above [for-each] will execute what ever is inside of it, once, for each child node inside of [_data]. In the video below, we are combining a [for-each] loop with the [pf.web.create-widget] Active Event to dynamically create HTML, according to a data segment. This data segment, could have been fetched from any arbitrary source, such as for instance our database, a remote source, or a file, etc. This allows you to dynamically build your HTML and web forms, according to whatever data you have available. The code I am executing at the end of the video, is included here for reference purposes;
_data foo1:Thomas Hansen foo2:John Doe foo2_5:"Error \r\nHansen" foo3:Jane Doe for-each:@/../*/_data/*(!/"=/Error/")?value _literal literal class:span-24 prepend-top innerValue set:@/./*/_literal/*/literal/*/innerValue?value source:@/././*/__dp?value append:@/../*/pf.web.create-widget/*/controls?node source:@/././*/_literal/*?node pf.web.create-widget:example1 class:span-24 controls literal innerValue:Hello World element:h1
Executing the above code, will produce an H1 element, followed by three paragraphs, containing the value of each node from inside our [_data] segment, minus the [foo2_5] node. This is because the NOT operator in our above expression, (!/”=/Error/”), excludes everything having “Error” as a part of its value, since it’s a regular expression iterator. Notice how I had to put my entire regex iterator inside of double quotes (“), since the regex iterator itself contains forwards slashes (/), which is a token in pf.lambda expressions.
When you create your iterators, then most of the time, you can just create them simply by starting them with a slash (/), and it will work out perfectly fine. However, if you need to use any of the characters below, inside your iterators, then you will need to put your entire iterator inside of double quotes;
This is because the above characters are “expression control characters”, which will either start a new iterator somehow, or in some other ways, end your current iterator. In addition, if your iterators needs to contain CR/LF characters, you will also need to put your iterators inside of double quotes, since there’s no way to define neither a CR nor a LF in an iterator, without putting these inside of a “string literal”. In later videos, I will walk you through exactly how string literals works in pf.lambda. However, if you’ve done some development in C#, you basically know this from before. Below is the video where I walk you through the concepts;
EDIT; Sorry for that the sound in my first version of this video disappeared at roughly 11 minutes. I’ve fixed this now …