Note: This plugin has been abandoned as Craft 4 includes Collections support., (*1)
Collections plugin for Craft CMS 3.x
Use Laravel Collections in Craft, (*2)
, (*3)
Requirements
This plugin requires Craft CMS 3.0.0-beta.23 or later., (*4)
Installation
To install the plugin, follow these instructions., (*5)
-
Open your terminal and go to your Craft project:, (*6)
cd /path/to/project
-
Then tell Composer to load the plugin:, (*7)
composer require superbig/craft3-collections
-
In the Control Panel, go to Settings → Plugins and click the “Install” button for Collections., (*8)
Collections Overview
Here is some good inspiration on what you can do with Collections:, (*9)
Configuring Collections
Add your macros to the config file:, (*10)
<?php
return [
/** Add your macros here
* "macros" => [
* 'toUpper' => function () {
* return $this->map(function ($value) {
* return strtoupper($value);
* });
* },
* ],
*
*/
"macros" => [
],
];
Using Collections
Add this macro to your config:, (*11)
<?php
return [
'macros' => [
'tagGroups' => function () {
return $this->groupBy(function ($tag) {
return substr($tag->title, 0, 1);
});
}
],
];
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.1.2/css/bulma.css">
</head>
<body>
Tags
Every tag on the site.
, (*12)
Tag groups
{% set collection = craft.tags.group('media') | collect %}
{% for letter, tags in collection.tagGroups() %}
{% endfor %}
</body>
</html>
Brought to you by Superbig, (*13)