Reusing data in Willow Loops

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 if or else or while.

Reusing data in Willow Loops

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 if or else or while.

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:

loop.willow

ui.php

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 đŸ™‚

Gist List
Get the Gist of things
Read the Comments
Open on github

Comments

No comments on this article yet.

Add a Comment

Your email address will not be published.

These HTML tags work: <a href=""> <code> <strong> <pre>


Connect:
OR

Our Services
Validate your ideas before diving in. Consultancy
Dig deep, audit your data, prepare for action Discovery
Get everything in shape to smooth the project path. Shaping
Let us help you realize your imagination Design
Rock-solid WordPress tools, built to last. Development
Without water, the garden will not grow. Support


Projects
Quinta de Sant’Ana, Portugal
Quinta de Sant’Ana, Portugal

Quinta de Sant'Ana overlooks the picturesque village of Gradil with its cobbled streets, white washed houses and hospitable inhabitants.


Projects: View All or
Releases
Willow
Willow

Willow is a Logic~less Template Engine built for WordPress. Willow plays nicely with ACF, is quick to learn and developer-focused.


Releases: View All or