Skip to content

Instantly share code, notes, and snippets.

@AugustMiller
Created May 18, 2015 04:08
Show Gist options
  • Save AugustMiller/2c3fe124d272541ff353 to your computer and use it in GitHub Desktop.
Save AugustMiller/2c3fe124d272541ff353 to your computer and use it in GitHub Desktop.
Kirby JSON Field Method
<?php field::$methods['json'] = function($field, $property = null) {
$data = (array)json_decode($field->value);
return ($property && isset($data[$property]) ? $data[$property] : $data);
};
@AugustMiller
Copy link
Author

This can be used to extract values from the Place Field Kirby Plugin.

@AugustMiller
Copy link
Author

If field data is encoded in JSON, you can get the entire associative array like this…

$page->location()->json();

…or a specific property thereof, like this:

$page->location()->json('address');
$page->location()->json('lat');
$page->location()->json('lng');

If the property is missing, the entire array will be returned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment