How to use Resultset filter in volt

I need user function filter in Resultset of model http://docs.phalconphp.com/en/latest/api/Phalcon%5Mvc%5Model%5Resultset%5Simple.html But i don't know how to write callback function in volt.

Please help me. Thank.



82.2k

Volt does not support anonymous functions, but you can still use PHP there:

<?php
$filtered = $robots->filter(function($robot){
    if ($robot->id < 3) {
        return $robot;
    }
});
?>

{% for robot in filtered %}{{ robot.name }}{% endfor %}

inb4: I would be great that Volt supports anonymous functions

edited Jul '14

Hi,

Thank for help but I can't use this way in my case

In controller i use Paginator

<?php

use Phalcon\Paginator\Adapter\Model as Paginator;

$paginator = new Paginator(array(
        "data" => $cats,
        "limit" => $limit,
        "page" => $numberPage
    ));

?>

And use in views:

{% for index,cat in page.items %} {{ cat.posts.filter({'status=published'}) | length }} {% endfor %}

Thank for help.