You are not logged in.
Pages: 1
Hi,
I'm getting a little bit confused when trying to use the "Parser" options on a module view. I want to be able to transform the value of a JSON field (a text field which is of type `name`) but having trouble working out exactly how I should be defining the output value.
Are there any examples I can look at which might give some clues?
Offline
I just had trouble with this yesterday. Great timing!
For a name input, by default you'll see something like this: {"last_name": "Doe","first_name": "John"} which is the `$value`.
To work with that in the parser function use json_decode($value, true). The true as the second parameter was the part throwing me off yesterday, as that's what converts the decoded json into an associative array.
Any data manipulation performed in the parser has to be re-assigned to `$value` to display in the module view.
So, to display "LastName, FirstName", the parser function would look something like this:
$new_value = json_decode($value, true);
$parsed_name = $new_value["last_name"] . ", " . $new_value["first_name"];
$value = $parsed_name;
Offline
Thanks! I'd tried json_decode but hadn't include the true parameter.
Offline
Pages: 1