psecio / slimtwig
带有预配置Twig的Slim分支
0.2
2019-05-12 12:10 UTC
Requires
- slim/slim: ^3.12
- slim/twig-view: ^2.5
This package is auto-updated.
Last update: 2024-09-12 23:22:53 UTC
README
自动包含Twig的Slim应用程序。
安装
要安装,请使用Composer
composer require psecio/slimtwig
使用方法
使用此库的方式与Slim和Slim-Twig类似。
<?php require_once __DIR__.'/vendor/autoload.php'; $app = new \SlimTwig\App(); $app->get('/', function() { $data = ['username' => 'ccornutt']; echo $this->view->out('template.php', $data); }); $app->run();
它假设您在与index.php
同一级别的目录中有一个templates
目录,但您可以通过设置进行配置
<?php $config = [ 'settings' => [ 'template_path' => __DIR__'/my/template/path' ] ] $app = new \SlimTwig\App();
建议在这里使用绝对路径,以避免相对路径混淆问题。