PHP code example of shallowred / kirby-collection-manager

1. Go to this page and download the library: Download shallowred/kirby-collection-manager library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

shallowred / kirby-collection-manager example snippets


// site/controllers/blog.php


use KirbyCollectionManager\CollectionController;

return function ($page) {
  return CollectionController::handle($page, [
    'collection' => $page->children()->listed(),
    'search' => [
      'fields' => ['title', 'text'],
    ],
    'taxonomies' => [
      ['param' => 'category', 'field' => 'category', 'label' => 'Category'],
    ],
    'pagination' => [
      'limit' => 10,
    ],
  ]);
};

// site/templates/blog.php
 snippet('collection-manager', compact('collection', 'config', 'snippets')) 

$data = $page->collectionManager(['pagination' => ['limit' => 6]]);

CollectionController::handle($page, [
  // The collection to manage: a Kirby collection object, or 'children'
  'collection' => 'children',
  'collectionMethod' => 'listed',   // used when collection is resolved from the page

  'search' => [
    'fields' => ['title', 'text'],  // fields to search
    'placeholder' => null,          // defaults to the translated placeholder
    'param' => 'q',                 // query param
  ],

  'taxonomies' => [
    [
      'param' => 'category',        // query param
      'field' => 'category',        // content field (comma-separated values supported)
      'label' => 'Category',
      'multiple' => false,          // true = multi-select (toggleable pills, comma-separated param)
    ],
  ],

  'pagination' => [
    'limit' => 10,
    'param' => 'p',                 // use a distinct param per instance on multi-collection pages
    'range' => 5,                   // number of page links
  ],

  'sorting' => [
    'default' => 'date',            // field, or 'field:direction'
    'direction' => 'desc',
    'options' => [],                // sort options offered to the visitor (whitelist)
    'param' => 'sort',
  ],

  'enableSearch' => true,
  'enableFilters' => true,
  'enableSorting' => false,         // 

'sorting' => [
  'default' => 'date',
  'direction' => 'desc',
  'options' => [
    'date' => 'Newest first',
    'date:asc' => 'Oldest first',
    'title:asc' => 'Title A→Z',
  ],
],
'enableSorting' => true,

CollectionController::handle($page, ['pagination' => ['param' => 'page-news'], ...]);
CollectionController::handle($page, ['pagination' => ['param' => 'page-events'], ...]);

'snippets' => ['item' => 'article-card'],

<!-- site/snippets/article-card.php -->
<article class="card">
  <h3><a href="<?= $item->url() 

CollectionController::handle($page, [
  'enableCss' => true,
  // ...
]);

<?= css(kirby()->plugin('shallowred/collection-manager')->asset('collection-manager.css')->url()) 

CollectionController::handle($page, [
  'classes' => [
    'item' => 'card bg-base-100 shadow-sm',
    'filter' => 'badge badge-outline',
    'filterActive' => 'badge-primary',
    'sortingSelect' => 'select select-sm',
    'searchInput' => 'input input-bordered',
  ],
  // ...
]);

'translations' => [
  'es' => [
    'collection.search.placeholder' => 'Buscar...',
    'collection.empty.title' => 'Sin resultados',
  ],
],