Skip to content

Instantly share code, notes, and snippets.

@craigcooperxyz
Last active December 7, 2015 23:29
Show Gist options
  • Save craigcooperxyz/84d089e8a9d8dfb08834 to your computer and use it in GitHub Desktop.
Save craigcooperxyz/84d089e8a9d8dfb08834 to your computer and use it in GitHub Desktop.
Kirby CMS British Pounds Sterling (GBP) Currency Field Method
<?php
// This field method for Kirby adds a method called GBP (Since extended to gbpsmall or gbplarge)
// Use it like this
// echo $page->price()->gbplarge()
// This example is intended for large figures such as £100,000 or £5,000, there are no decimal places
field::$methods['gbplarge'] = function($field) {
return '£' . number_format($field->value, 0, '.' , ',' );
};
// This example is intended for smaller figures such as £99.99 or £2.99, there are two decimal places
field::$methods['gbpsmall'] = function($field) {
return '£' . number_format($field->value, 2, '.' , ',' );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment