facelordgists
3/31/2015 - 8:24 PM

Kirby Toolkit stuff to use

Kirby Toolkit stuff to use

Check if a string contains a string

http://getkirby.com/docs/toolkit/api/str/contains

//str::contains($str, $needle, $i = true);

$string = "This is a long string with a DooHicky inside";
$needle = "doohicky";
$doohicky_status = str::contains($string, $needle);

Sitewide configuration variables

c::set and c::get

If you need some app-wide configuration variables you can either use constants or you can go for Kirby's config variables. They are accessible everywhere and can be set and overwritten everywhere as well.

c::set('myconfigvar', 'this is my awesome config value');

function foo() {

  echo c::get('myconfigvar');
  // result: 'this is my awesome config value'

}

If you want to check, which config variables have been defined so far, do this:

a::show(c::get());

// output: your entire config

String splitting using str::split

$string = ', design, tags, typography, fun, , ';
$tags   = str::split($string);

a::show($tags);

/*

Array
(
    [0] => design
    [1] => tags
    [2] => typography
    [3] => fun
)

*/

Or change the splitting character:

$string = '/ design / tags / typography / fun / / ';
$tags   = str::split($string, '/');

Even specify the minimum length of the string

$string = '/ design / tags / typography / fun / / ';
$tags   = str::split($string, '/', 4);

a::show($tags);

/* output:

Array
(
    [0] => design
    [1] => tags
    [2] => typography
)

*/