Created
May 18, 2015 04:08
-
-
Save AugustMiller/2c3fe124d272541ff353 to your computer and use it in GitHub Desktop.
Kirby JSON Field Method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php field::$methods['json'] = function($field, $property = null) { | |
$data = (array)json_decode($field->value); | |
return ($property && isset($data[$property]) ? $data[$property] : $data); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If field data is encoded in JSON, you can get the entire associative array like this…
…or a specific property thereof, like this:
If the property is missing, the entire array will be returned.