[TYPO3-mvc] Invoking fluid outside the automatic call in controllers
Steffen Ritter
info at rs-websystems.de
Sun Nov 29 11:23:22 CET 2009
now to the right list...
Hey list,
for all who probably might need this, I'll provide a function which
renders a template file with fluid and returns the rendered string.
Me - for example - use this in may Repository. Wondering why:
I extended the "update" function, so that "onUpdate" of every Object I
can write it's representation to file system.
In my special case im writing an apache vhost config file to the
filesystem on saving the "vhost" object.
I hope this might be useful to someone. I think this also could work
from eId oder cli (not tested).
regards
Steffen
/**
* renders the given Template file via fluid rendering engine.
* You might encounter problems with viewhelpers, since no controller
context is set.
*
* @param string $templateFile absolute path to the template File
* @param array $vars an array of all variables you want to assgin to
the view f.e: array('blog'=> $blog, 'posts' => $posts)
*
* @return string of the rendered View.
*/
protected function renderFileTemplate($templateFile, array $vars) {
$templateParser =
Tx_Fluid_Compatibility_TemplateParserBuilder::build();
$objectFactory =
t3lib_div::makeInstance('Tx_Fluid_Compatibility_ObjectFactory');
$templateContent = file_get_contents($templateFile);
if ($templateContent !== false) {
$content = $templateParser->parse($templateContent);
$variableContainer =
$objectFactory->create('Tx_Fluid_Core_ViewHelper_TemplateVariableContainer',
$vars);
$renderingConfiguration =
$objectFactory->create('Tx_Fluid_Core_Rendering_RenderingConfiguration');
$renderingContext =
$objectFactory->create('Tx_Fluid_Core_Rendering_RenderingContext');
$renderingContext->setTemplateVariableContainer($variableContainer);
$renderingContext->setRenderingConfiguration($renderingConfiguration);
$data = $content->render($renderingContext);
return $data;
}
}
More information about the TYPO3-project-typo3v4mvc
mailing list