Question

Templating with Flow3 is done using Fluid templating language.

Is there an integrated/easy solution to use PHP templates instead? (without having to write a template renderer myself)

(to avoid misunderstandings: by PHP template I mean HTML code mixed with PHP)

Was it helpful?

Solution

The whole point of fluid is not to do this. You can write own viewhelpers for that.

A fast workaround would be to write a php viewhelper which uses eval(). But that would be really bad from a security point of view.

OTHER TIPS

Your controller has a protected property, that defaults to Fluid, changing it to something else is really easy:

    protected $viewFormatToObjectNameMap = array('json' => '\TYPO3\FLOW3\MVC\View\JsonView');

Now take a look at the EmptyController in the same directory: \TYPO3\FLOW3\MVC\View\

You can use this as start. What you basically have to do is to satisfy an assign method, the way how you can transfer variables to your theme.

Next, come up with a few standardizations (e.g. the Template-Files have to be in the folder \Resources\Private\Templates\ControllerName\ActionName.phtml, note the file extension) and say which variable will be available there (e.g. $view).

Now a very basic approach would be:

    protected $view = array();

    public function assign($key, $value) {
        $this->view[$key] = $value;
    }

    public function render() {
        $this->controllerContext->getResponse()->setHeader('Content-Type', 'text/html');

        $view = $this->view;
        ob_start();         

        include_once($this->getTemplatePathAndFilename());
        $output = ob_get_contents();
        ob_end_clean();
        return $output;
   }
}

For the $this->getTemplatePathAndFilename() function, you can use the code from the TYPO3\Fluid\View\TemplateView->getTemplatePathAndFilename() method and adjust it to your needs.

In your template files, you can now use the $view variable.

I'm at my parents for easter and they lack a runtime environment, so this is not tested and you'll likely run into problems, but this should get you started!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top