Skip to content
Kirby Tag and Page Method to generate various random values
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
classes
vendor
.editorconfig
.gitignore
.php_cs.dist
composer.json
composer.lock
index.php
readme.md

readme.md

Kirby 3 Random

GitHub release License Kirby Version Kirby 3 Pluginkit

Kirby Tag and Page Method to generate various random values.

Commercial Usage

This plugin is free but if you use it in a commercial project please consider to

Installation

  • unzip master.zip as folder site/plugins/kirby3-random or
  • git submodule add https://github.com/bnomei/kirby3-random.git site/plugins/kirby3-random or
  • composer require bnomei/kirby3-random

Migrating tag use from Kirby V2 to V3

The type attribute is a reserved keyword for Kirby Tags in Kirby CMS V3. You need to replace type with kind.

// V2
(random: 5 type: alpha)
// V3
(random: 5 kind: alpha)

Also the Site Methods has been replaced with a Page Method.

ATTENTION: Page method not working (yet). issue pending.

// V2
echo $site->random('red, green, blue, black, white, yellow', 'pool', 3);

// V3
echo $page->random('red, green, blue, black, white, yellow', 'pool', 3);

Usage

Random string using Kirby Toolkit str::random() forwarding the type if any.

(random: 5) or (random: 5 kind:alpha)

Random positiv non-zero number with max value inclusive using PHP random_int() (or rand() in php5).

(random: number length: 128)

Any one value of a comma seperated list.

(random: apple, banana, coconut)

Any random pool of values picked from a comma seperated list with optional length.

(random: red, green, blue, black, white, yellow kind: pool)
or
(random: red, green, blue, black, white, yellow kind: pool length: 3)

A number between a min and max value inclusive using PHP random_int() (or rand() in php5).

(random: 41, 53 kind: between)

Lorem Ipsum text using a generator.

(random: lorem length: 5) or (random: lorem kind: words length: 4)
(random: lorem kind: sentences length: 3)
(random: lorem kind: paragraphs length: 2)
(random: lorem kind: chars length: 140)

Token

(random: token kind: number upper length: 12)

The plugin also adds a $page->random() function to use in templates etc.

// STRING
echo $page->random(23);

// NUMBER
echo $page->random([41, 53], 'between');

// POOL
// from a comma seperated string
echo $page->random('red, green, blue, black, white, yellow', 'pool', 3);
// or a php array
echo $page->random($myArray, 'pool', 3);

// LOREM
echo $page->random('lorem', 'paragraphs', 3);

// Token: upper, lower, numbers
echo $page->random('token', 'lower,numbers', 5); // d63jd
echo $page->random('token', 'lower,upper', 5); // GjHoL

Disclaimer

This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please create a new issue.

License

MIT

It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.

You can’t perform that action at this time.