I've created a field type that stores its value as a model. That model’s __toString()
method returns the result of a craft()->templates->render()
call:
public function render()
{
$render = craft()->templates->render('myplugin/templates/mymodeltemplate');
return $render;
}
public function __toString()
{
return $this->render();
}
When I output the model from a template, like so:
{{ entry.myField }}
Twig encodes the resulting HTML as a string with HTML entities. Running the string through html_entity_decode()
before returning it in __toString()
doesn't help. I'm assuming this string formatting is happening somewhere at the Twig level.
Being new to Craft, I'd love to understand a little more of what's going on here. How does the string representation of an element model get passed to and handled by Twig?