[TYPO3-mvc] How can I give content to a ViewHelper when using alternative syntax?

Oliver Salzburg oliver.salzburg at googlemail.com
Fri Aug 3 16:39:43 CEST 2012


On 2012-08-03 00:45, Claus Due wrote:
> Hi Oliver, Valentin,
> 
> FYI: you cannot place a Fluid template piece inside some string which is stored in a Fluid variable or is not otherwise explicitly (which usually means manually) parsed as if it were a Fluid template (and as such, the string being parsed would require namespace definitions to be added, support for Layout if one is used etc. etc.). The string would not be rendered even if it was not escaped (that would require horrible two-pass parsing or some trickery).
> 
> This means you a) cannot have your ViewHelpers executed and b) cannot reference your variables if you store a piece of Fluid inside something that is output through Fluid but not parsed manually. Bad situation. It's rather a mess to achieve this sort of behavior especially when combined with RTE, because the RTE processing will _always_ damage your syntax due to wanting to encode special chars which include < and >.
> 
> You _may_ be able to…
> 
> * Create a new ViewHelper which renders child content, then takes that content and renders a StandaloneView - but trust me, this will most likely open up a huge can of worms if you rely on a ControllerContext and will surely hinder performance.
> * In the ViewHelper do $standaloneView->assignMultiple($this->templateVariableContainer->getAll());
> * $namespaces = '{myext=Tx_MyExt_ViewHelpers}'; // note you must manually add all namespaces as such.
> * $standaloneView->setTemplateSource($namespaces . html_entity_decode($this->renderChildren()));
> * return html_entity_encode($standaloneView->render());
> 
> …which is quite a lot to do just to be able to use a Fluid variable and ViewHelper in a record's field. Any errors, and you destroy the output (unless you catch and treat exceptions - and then output some useful alternative representation without using Fluid which is kind of back to square one).
> 
> I'd advise against the above solution - but present it so that it will give you some idea about why what you are trying is not a good idea ;)
> 
> 
> Cheers,
> Claus

Hello Claus,

thank you very much for your detailed reply.

While this is all very insightful, I wouldn't dare to try to implement
that, just to render a single link on a single page.

But, on the other hand, I slowly see myself running out of options with
this one :(

I had the idea of simply writing my own ViewHelper that only renders a
link, but takes the content, not from its children, but from a
parameter passed to it. Then I could use *that* ViewHelper to render my
link.

But I also don't understand how to even approach that. Where would I
put said ViewHelper so that it is even found by "the system"?
Or better yet, how can I tell the "the system" about the existence of
my ViewHelper?

Understanding that might already bring me a tiny step closer to putting
this issue to rest.

Cheers
Oliver


More information about the TYPO3-project-typo3v4mvc mailing list