用 Plates 替换 FlightPHP 中的模板引擎
Replace template engine in FlightPHP with Plates
FlightPHP 文档概述了如何将模板引擎切换到 Smarty,但我该如何切换到 Plates?我已经通过 composer 及其自动加载添加了 Plates。
来自自定义视图部分:https://flightphp.com/learn#views
<?
Flight::register('view', 'Smarty', array(), function($smarty){
$smarty->template_dir = './templates/';
$smarty->compile_dir = './templates_c/';
$smarty->config_dir = './config/';
$smarty->cache_dir = './cache/';
});
?>
如何从此处添加 Plates 引擎?
https://platesphp.com/engine/overview/
Plates 的过程与 Smarty 的过程完全相同:
<?php
require '../lib/vendor/autoload.php';
// Register Plates as the template engine
Flight::register('view', 'League\Plates\Engine', ['../lib/templates']);
// Override the default render method
Flight::map('render', function($template, $data){
echo Flight::view()->render($template, $data);
});
Flight::route('/', function ()
{
// Render the Plates template using Flight's render method
Flight::render('hello', ['name' => 'World']);
});
Flight::start();
FlightPHP 文档概述了如何将模板引擎切换到 Smarty,但我该如何切换到 Plates?我已经通过 composer 及其自动加载添加了 Plates。
来自自定义视图部分:https://flightphp.com/learn#views
<?
Flight::register('view', 'Smarty', array(), function($smarty){
$smarty->template_dir = './templates/';
$smarty->compile_dir = './templates_c/';
$smarty->config_dir = './config/';
$smarty->cache_dir = './cache/';
});
?>
如何从此处添加 Plates 引擎? https://platesphp.com/engine/overview/
Plates 的过程与 Smarty 的过程完全相同:
<?php
require '../lib/vendor/autoload.php';
// Register Plates as the template engine
Flight::register('view', 'League\Plates\Engine', ['../lib/templates']);
// Override the default render method
Flight::map('render', function($template, $data){
echo Flight::view()->render($template, $data);
});
Flight::route('/', function ()
{
// Render the Plates template using Flight's render method
Flight::render('hello', ['name' => 'World']);
});
Flight::start();