Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

How to use the :: syntax

Started by Muut Archive 9 years ago · 3 replies · 388 views
9 years ago

Class::methiod is a short way to indicate a method inside a class. It's not a valid syntax to be used anywhere (except when the method is static).

Actual usage depends on where you want to use it. In Twig, use collection.order(), in PHP use $collection->order()

9 years ago

Thanks Flavio. Success at last. For anyone else trying to re-order a collection programmatically in a Twig template, try this:

TWIG
{% set collection = page.evaluate([{'@page.children':'/crimebooks'}]) %}
{% set orderedcoll = collection.order('header.pub','asc') %}

Where pub is a header variable containing an integer. This code creates a new collection collection from the children of the page /crimebooks and then creates another collection orderedcoll which has been put into ascending order of the value of the header variable pub (publication date in my case).

The code can probably be made more elegant but it works. Thanks again.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1334 9 years ago
Archive · by Muut Archive, 9 years ago
2 924 9 years ago
Archive · by Muut Archive, 9 years ago
2 4055 9 years ago
Archive · by Muut Archive, 9 years ago
1 2938 9 years ago
Archive · by Muut Archive, 9 years ago
3 1111 9 years ago