Comment by Mauricio Sánchez, 2015-01-25 19:17
The line 15 of the Viewing content code example should be:
$field = $content->getField( $fieldDefinition->identifier );
As in the command line version example: https://github.com/ezsystems/CookbookBundle/blob/master/Command/ViewContentCommand.php.