I have not been able to solve this specific case from the examples provided in the documentation.
I create a Result:
Customer customer = new Customer("James");
Order[] orders = new Order[2];
orders[0] = new Order("Apple");
orders[1] = new Order("Orange");
Content html = views.html.template.render(customer, orders);
return ok(html);
And my template is:
@(customer: Customer, orders: Array[Order])
<h1>Welcome @customer.name!</h1>
<ul>
@for(order <- orders) {
<li>@order.name</li>
}
</ul>
Now I want to add a Boolean variable in the template, then iterate through the orders, and if Apple appears in the orders, I want to set the created variable to true.
Basically I need a var that has scope throughout the whole template.
Thank you.
Added some pseudocode.
@(customer: Customer, orders: Array[Order])
<h1>Welcome @customer.name!</h1>
**** var containsApple = false;
<ul>
@for(order <- orders) {
<li>@order.name</li>
**** if order.name == "apple"
**** containsApple = true;
}
</ul>
booleanfor), we could help find an alternative route to your goal?