Willow is a logic-less Template Engine, which means that there are no commands or functions to change how data is used conditionally – for example
This is by design, to keep the logical work of preparing and validating data outside of the templates – in controller classes.
However, Willow provides a simpler concept – Loops which allow templates to iterate over a data set, applying markup and filters to returned values.
Willow allows you to format and loop over data once it has been collected and validated via a Get method – the following example show how to loop over an array of data and how the same data can be used multiple times and formatted differently inside each loop.
We only need to two files to generate, fetch and display data – firstly a template file – in this example called loop.willow and then a controller file – called ui.php ( as we’ll be extending the ui context ) – you can see both below:
The results would return a very simple html document – in the example below called loop.html:
As you can see, the data can be reused and formatted differently in each loop without affecting how it is displayed in subsequent loops – scope data can also be reused in separate Willow tags – to find out more, read the documentation.
Happy coding 🙂
No comments on this article yet.