Looper API

This is a technical article of what is offered by our Looper API.

Loopers offer the perfect way to loop through dynamic data. Whether it is an array of strings or nested objects, loopers will have you covered.

How to create a Custom Looper

Through Dynamic Content

If you setup a Dynamic Content filter that returns an array. You can then loop through that as it's own Looper Provider. Setting that up would look something like this.

Looper from Dyanmic Content in Cornerstone UI

Through Custom Looper API

All custom looper filters are prefixed with cs_looper_custom_. The first argument being data from a prior looper or from Cornerstone. It is what you will filter if that is valid, however you can always just return the data you want to use. The second arguments is the json decoded data that is passed in the Cornerstone UI.

In this example we are reading XML data that could be from an RSS feed. The looper is called rss and will be referenced in the UI as such. In Cornerstone we are expecting url to be passed as a key value JSON pair. The XML has a channel node and in that node we want to loop through item nodes.

<?php // Custom Looper `rss` // Add a filter which Cornerstone can use // We then reference this just as `rss` in the Custom Looper UI add_filter("cs_looper_custom_rss", function($result, $args = []) { // Grab data from URL $rss = file_get_contents($args['url']); // Decode XML // needs php-xml installed $xml = new SimpleXMLElement($rss); // Grab array of item $items = $xml->channel->item; $out = []; // Loop and convert to array // as that can sometimes be easier to work with // then a class object foreach ($items as $item) { $out[] = (array)$item; } // return data to loop through return $out; }, 10, 2);
Cutom Looper in Cornerstone UI

See something inaccurate? Let us know