Loops in a Template
This lesson will cover how to pass array values into a template using a loop.
We'll cover the following...
You can pass in an array of values into a template and loop through them.
Project example
Let’s take a look at an example of how to do that:
%{ for addr in ip_addrs ~}
backend ${addr}:${port}
%{ endfor ~}Project example for loops in template
This time we are just rendering the template straight to the output. Notice that we are passing in an array for ip_addrs. Let’s look at the code in more detail:
-
In the template, we loop around the
ip_addrs...
Ask