DLight\Application\Drive\View\TwigDrive

Mô tả: view engine dùng Twig (twig/twig). Tự thêm extension .twig nếu thiếu. Có thể đăng ký function qua option functions.

Public API

  • __construct(string $viewPath, array $options = [])
  • render(string $template, array $data = []): string

Cấu hình & demo

<?php // config/view.php
return [
  'engine' => 'twig',
  'view_path' => ROOT_DIR . 'resource/view/',
  'drives' => [
    'twig' => [
      'class' => DLight\\Application\\Drive\\View\\TwigDrive::class,
      'options' => [
        'cache' => false,
        'functions' => [
          'asset' => fn($p) => '/assets/' . ltrim($p, '/'),
        ],
      ],
    ],
  ],
];
use DLight\Application\View;
echo View::render('client/home', ['name' => 'Twig']);