Is the method ofType usable in a collection defined with twig syntax?

Hi,

I would like to filter content based on type; I saw the Collection::ofType($type) filter that seems to do what I expect.

But I canโ€™t manage to use it so far to display the 5 latest classified :

        {% set latest_classified = page.collection({
                'items': '@root.descendants',
                'order': {
                    'by': 'date',
                    'dir': 'desc'
                },
                'limit': 5,
                'ofType':'classified',
            })
        %}

On collection page, there is a PHP example but I would like to keep in a Twig universe:

$collection = new Collection();
$collection->setParams(['taxonomies' => ['tag' => ['dog', 'cat']]])->dateRange('01/01/2016', '12/31/2016')->published()->ofType('blog-item')->order('date', 'desc');

Thanks,
Nicolas

The other syntax that would look good to me would be:

        {% set latest_classified = page.collection({
                'items': {
                    'ofType': 'classified',
                },
                'order': {
                    'by': 'date',
                    'dir': 'desc',
                },
                'limit': 5,
            })
%}

But it does not work either.

Also tried from https://github.com/getgrav/grav/issues/1097:

{% set latest_classified = page.collection().ofType('classified')
%}

But no results too :frowning: :โ€™(

Ok, this works:

{% for child in page.children.order('date', 'desc').ofType('album') %}
...
{% endfor %}

So seems my issue is more on the way I build my collection before the filter applies.

Ok found the right syntax :smiley:

        {% set latest_classified = page.collection({
                'items': '@root.descendants',
                'order': {
                    'by': 'date',
                    'dir': 'desc',
                },
                
            })
            .ofType('classified')
            .slice(0,5)
        %}