所以我正在建立自己的框架,目前纯粹用于学习目的
https://bitbucket.org/benshepherd/ben-mvc/src
我有一个位于Layouts/default.html
的布局文件,视图内容通过布局中的变量{{content}}
加载。我试图在布局中包含导航栏。
{% include 'nav.html' %}
//Outputs
nav.html
{% include 'Layouts/nav.html' %}
//Outputs
Layouts/nav.html
我是树枝的新手,无法弄清楚为什么它不起作用。有什么想法吗?
我的代码:
<?php
// autoload.php @generated by Composer
require_once __DIR__ . '/composer' . '/autoload_real.php';
ComposerAutoloaderInit20fe888ccd463c432bf202972c5e1e6c::getLoader();
// Load your libraries below
//twig
$loader = new Twig_Loader_String();
$twig = new Twig_Environment($loader, array('debug' => true));
$twig->addExtension(new Twig_Extension_Debug());
//mysql
$dbConn = new \Simplon\Mysql\Mysql('localhost', 'root', '', 'test');
$sqlManager = new \Simplon\Mysql\Manager\SqlManager($dbConn);
$sqlBuilder = new \Simplon\Mysql\Manager\SqlQueryBuilder();
答案 0 :(得分:1)
您正在使用StringLoader
,因此,如果您要包含文件,那么您实际上是包含字符串。
改为使用Twig_Loader_FileSystem
加载程序:
<?php
// ...
//twig
$loader = new Twig_Loader_FileSystem(__DIR__.'/Layouts'); // doublecheck the path
$twig = new Twig_Environment($loader, array('debug' => true));