Wrapper around render() for twig printed output.
If an object is passed that has no __toString method an exception is thrown; other objects are casted to string. However in the case that the object is an instance of a Twig_Markup object it is returned directly to support auto escaping.
If an array is passed it is rendered via render() and scalar values are returned directly.
mixed $arg: String, Object or Render Array
The rendered output or an Twig_Markup object.
render
TwigNodeVisitor
function twig_render($arg) {
if ($arg instanceof TwigReference) {
$arg =& $arg
->getReference();
}
// == is true also for empty arrays
if ($arg == NULL) {
return NULL;
}
// Keep Twig_Markup objects intact to prepare for later autoescaping support
if ($arg instanceof Twig_Markup) {
return $arg;
}
if (is_scalar($arg)) {
return $arg;
}
if (is_object($arg)) {
if (method_exists($arg, '__toString')) {
return (string) $arg;
}
throw new Exception(t('Object of type "@class" cannot be printed.', array(
'@class' => get_class($arg),
)));
}
// This is a normal render array.
return render($arg);
}