Smarty Template Bridge

Installation

composer require larafony/view-smarty

Configuration

use Larafony\View\Smarty\ServiceProviders\SmartyServiceProvider;

$app->withServiceProviders([
SmartyServiceProvider::class
]);

Template Example

{* resources/views/smarty/welcome.tpl *}
{extends file="layout.tpl"}

{block name="title"}Welcome{/block}

{block name="content"}
<h1>Hello {$name}!</h1>

{if $user->isAdmin()}

You have admin access.

{/if}

{foreach $items as $item}
- {$item.name} - {$item.price|number_format:2}

{/foreach}

{/block}

Usage in Controller

use Larafony\View\Smarty\SmartyRenderer;

final class HomeController extends Controller
{
#[Route('/', methods: ['GET'])]
public function index(SmartyRenderer $smarty): ResponseInterface
{
$html = $smarty->render('welcome.tpl', [
'name' => 'John',
'items' => Item::all(),
]);

return new Response(200, [], $html);
}
}

Features