You have probably already used a For each…End for each loop to work with ORDA entity selections or with collections. Its use is simple and straight forward. Would like to use it as a 4D tag in your SHTML pages? Or perhaps with the PROCESS 4D TAGS command?
As of 4D v19, you can! Keep reading to learn more.
A new 4D tag is now available: the 4DEACH tag.
Its use is very similar to a For each…End for each loop.
Just a reminder
Here is a simple example to remind you how to use a For each…End for each loop on an entity selection:
var $customer : cs.CustomersEntity
For each ($customer; ds.Customers.all())
$customer.name:=Uppercase($customer.name)
$customer.save()
End for each
and now let’s use the new 4DEACH tag
In this blogpost, we showed you how to put some data related to the user in the web session. For example, a salesperson’s top three customers.
The following is the SHTML code to display these top three customers (Session.storage.myTop3) which is an entity selection.
We can verify the 4DEACH tag allows looping through it.
customers.shtml file:
<table class="table">
<tr><th>Name</th><th>Total purchase</th></tr>
<!--#4DEACH $customer in Session.storage.myTop3-->
<tr>
<td ><!--#4DTEXT $customer.name--></td>
<td ><center><!--#4DTEXT String($customer.totalPurchase;"$###,##0")--></center></td>
</tr>
<!--#4DENDEACH-->
</table>
And here is the result:
As you can see, the syntax is very similar to a For each…End for each loop.
The tag also works for collections and objects (to loop through an object’s properties).
It’s also supported by the PROCESS 4D TAGS and WEB SEND FILE commands.
Download the HDI above to play with this new tag and join the discussion on the 4D forum!