* * * Displayed only if the JSON decode worked. Much more code and many more * ViewHelpers can go here. Now, imagine that this block spans so much code * that potentially there could come an Exception from many additional places * (for example from Widgets) and you cannot be sure where the Exception comes * from but still want to tell the user what exactly went wrong and provide * an error code which makes sense to send to developers if problems persist: * *

* Error in "{exception.trace.0.class * -> v:iterator.explode(glue: '_') * -> v:iterator.pop() * -> v:format.replace(substring: 'ViewHelper', replacement: ''}" * {exception.code} * *

*

* {exception.message} * *

*
 *                 Value: ``{exception.trace.0.args.0}´´
 *                 
 *             
*
* * ...or if you want a shorter version... * * {v:try(then: '{badObject -> v:format.json.encode()}', else: '{"validJson": "validValue"')} * * * @author Claus Due * @package Vhs * @subpackage ViewHelpers */ class TryViewHelper extends AbstractConditionViewHelper { use TemplateVariableViewHelperTrait; /** * @return mixed */ public function render() { try { $content = $this->renderThenChild(); if (TRUE === empty($content)) { $content = $this->renderChildren(); } } catch (\Exception $error) { $content = $this->renderChildrenWithVariables(array('exception' => $error)); } return $content; } }