微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

用 Plates 替换 FlightPHP 中的模板引擎

如何解决用 Plates 替换 FlightPHP 中的模板引擎

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();

enter image description here enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。