PHP code example of hananils / kirby-link-methods

1. Go to this page and download the library: Download hananils/kirby-link-methods 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/ */

    

hananils / kirby-link-methods example snippets


// using the username
$users->toList();

// using the page title
$pages->toList();

// using the filename
$files->toList();

// numeric list, returns "2010–2012, 2022" for "2010, 2011, 2012, 2022"
$page->years()->toNumericList();

// numeric list with "since", return "since 2020" for "2020, 2021, 2022"
$page->years()->toNumericList(true);

// using the custom method `nickname`
$users->toList('nickname');

// using the field category
$pages->toList('category');

// with numeric values
$pages->toNumericList('date');

// creates, a, list, with, commas and conjunction
$pages->toList('title', true)

// creates, a, list, with, commas & conjunction
$pages->toList('title', '&')

// link everything to the same URL
$pages->toList('title', true, 'https://example.com');

// link all pages to their own URL
$pages->toList('title', true, '{{page.url}}');

// link all pages to a custom URL
$pages->toList('title', true, 'my-custom-path/{{page.category}}');

// link all pages to a custom URL with numeric values
$pages->toNumericList('date', true, 'my-year-overview/{{page.date.toDate('Y')}}');


// Given the fields name and job, creates "Jane Doe, astrophysicist"
echo $user->asList(['name', 'job']);

// Given the fields start and end, creates "2020–2023"
echo $page->asNumericList(['start', 'end']);

//  Given the fields name and job, creates "Jane Doe: astrophysicist"
echo $page->asList(['name', 'job'], ': ');

// Create a Choices collection for instance, see https://github.com/hananils/kirby-choices
$choices = $page->categories()->toChoices();

// Convert all choices to a comma-separated list
echo $choices->toList();

// Convert all choices to a comma-separated list with the default conjunction
echo $choices->toList(true);

// Convert all choices to a comma-separated list with a custom conjunction
echo $choices->toList('&');

$data = ['this', 'that'];

// this, that
naturalList($data);

// this and that
naturalList($data, true);

// this & that
naturalList($data, '&');

$data = [2019, 2020, 2021, 2022];

// 2019-2022
numericList($data);

// since 2022
numericList($data, true);