Skip to content

jdifool/tempest-fluid-view

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Fluid template engine for Tempest PHP

This package allows to use the Fluid template engine in a Tempest application.

Usage

First install this Fluid view renderer package (it also installs the required Fluid engine provided by the typo3fluid/fluid package):

composer require jdifool/tempest-fluid-view

The next step is to provide the configuration needed for Fluid to find your view files.

<?php
// app/fluid.config.php

declare(strict_types=1);

use Jdifool\Tempest\View\Renderers\FluidConfig;

return new FluidConfig(
    templateRootPaths: [
        __DIR__ . '/../views/Templates/',
    ],
    partialRootPaths: [
        __DIR__ . '/../views/Partials/',
    ],
    layoutRootPaths: [
        __DIR__ . '/../views/Layouts/',
    ]
);

Finally, update the view configuration to use the Fluid view renderer:

<?php
// app/view.config.php

declare(strict_types=1);

use Tempest\View\ViewConfig;
use Jdifool\Tempest\View\Renderers\FluidViewRenderer;

return new ViewConfig(
    rendererClass: FluidViewRenderer::class
);

In your controller you can now use Fluid templates like so:

<?php
// app/HomeController.php

namespace App;

use Tempest\Router\Get;
use Tempest\View\View;
use function Tempest\view;

final readonly class HomeController
{
    #[Get('/')]
    public function __invoke(): View
    {
        $data = ['foo' => 'bar'];

        // __DIR__ . '/../views/Templates/Home/Index.html'
        return view('Home/Index', ...$data);
    }
}

About

A Fluid view renderer for Tempest PHP

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages