RSS Feed

Fluid without Extbase

12. Februar 2010, geschrieben von modi 3 Kommentare »

Thinking about a flexible solution for an email template, I found a interesting suggestion in a presentation by Patrick Lobacher of typofaktum. On slide 39 he has posted some code to use Fluid without Extbase. Based on his code, I ended up using this code:

$renderer = t3lib_div::makeInstance('Tx_Fluid_View_TemplateView');
$renderer->setControllerContext(t3lib_div::makeInstance('Tx_Extbase_MVC_Controller_ControllerContext'));
$template = t3lib_extMgm::extPath(strtolower($this->extensionName)) . 'Resources/Private/...';
$renderer->setTemplatePathAndFilename($template);
$renderer->assign('helloworld', $helloworld);
$rendered = $renderer->render();

If you get an error stating that the renderer expected an Extbase object but was boolean, you should check for a typo in your $template path.

Patrick also uses $_EXTKEY to get the extension path, but in my controller the variable is not available. In my case, “strtolower($this->extensionName)” fits the extension key perfectly so I chose to use it to get the correct path.

Since I did not want to send HTML mails and my Fluid Template, I use the rendered result to pass it to t3lib_htmlmail’s “addPlain($mailBody)” function to send my email.

Update:
For newer Extbase-Versions you have to use t3lib_div::makeInstance(‘Tx_Fluid_View_StandaloneView’);!
See: http://forge.typo3.org/projects/typo3v4-mvc/wiki/FLUIDTEMPLATE_Content_Object

 

3 Antworten to “Fluid without Extbase”

  1. Andreas sagt:

    In TYPO3 4.4 beta3 I found a solution for bug
    http://forge.typo3.org/issues/show/7176

    $renderer = t3lib_div::makeInstance(‘Tx_Fluid_View_TemplateView’);
    $controllerContext = t3lib_div::makeInstance(‘Tx_Extbase_MVC_Controller_ControllerContext’);
    $controllerContext->setRequest(t3lib_div::makeInstance(‘Tx_Extbase_MVC_Request’));
    $renderer->setControllerContext($controllerContext);
    $template = t3lib_extMgm::extPath($this->extKey) . ‘Resources/Private/register.tmpl’;
    $renderer->setTemplatePathAndFilename($template);
    $renderer->assign(‘helloworld’, $helloworld);
    $rendered = $renderer->render();

  2. Thomas sagt:

    Hi,
    wenn ich es richtig sehe, müsste es:
    t3lib_extMgm::extPath(t3lib_div::camelCaseToLowerCaseUnderscored($this->extensionName))

    heißen, und nicht:
    t3lib_extMgm::extPath(strtolower($this->extensionName))

    LG,
    Thomas

Antworten