Twig扩展不起作用

时间:2015-12-05 03:46:10

标签: twig

我正在尝试首次设置新的树枝工作流程。

我目前正在开发使用xampp的Mac Book Pro,El Capitan OS。

我需要twig文件:base.twig和index.twig。我希望索引扩展基数,所以我的索引如下所示:

<!doctype html>
<html lang="">
  <head>
    {% block head %}
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="description" content="">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <title>Web Project Template</title>
    {% endblock %}
  </head>
  <body>
    {# header #}
    <header class="header header__main">
      {% block header %}
      {% endblock %}
    </header>

    {# content #}
    <main class="content content__main">
      {% block content %}
      {% endblock %}
    </main>

    {# footer #}
    <footer class="footer footer__main">
      {{ include('../../app/Resources/views/partials/footer.twig') }}
    </footer>

  </body>
</html>

这两个文件都位于我的../app/Resources/views/文件夹中,但是当我使用浏览器检查我的页面时,它只返回我的base.twig的内容。

这是我的基础.twig:

<?php
require __DIR__.'/vendor/autoload.php';
/*
 * Go to this file in your web-browser to render Twig templates:
 *
 *  * http://localhost/index.php            -> index.twig
 *  * http://localhost/index.php/contact    -> contact.twig
 *
 * ... etc ...
 */
// 1) create a Symfony Request, used only to help make each URL render a different Twig template
use Symfony\Component\HttpFoundation\Request;
$request = Request::createFromGlobals();
$uri = $request->getPathInfo();
// 2) bootstrap Twig!
$loader = new Twig_Loader_Adapter(__DIR__.'/');
$twig = new Twig_Environment($loader, array(
    // cache disabled, since this is just a testing project
    'cache' => false,
    'debug' => true,
    'strict_variables' => true
));
$twig->addExtension(new Twig_Extension_Debug());
// 3) create a few different "pages"
switch ($uri) {
    // The Homepage! (/)
    case '/':
        echo $twig->render('../../app/Resources/views/base.twig', array(
            'pageTitle' => 'Suit Up!',
        ));
        break;
    // All other pages
    default:
        // if we have anything else, render the URL + .twig (e.g. /about -> about.twig)
        $template = substr($uri, 1).'.twig';
        echo $twig->render($template, array(
            'title' => 'Some random page!',
        ));
}

?>

这是我的index.php,我在其中呈现模板:

import System.Process (createProcess, proc, shell, CreateProcess)
import Text.Printf (printf, PrintfArg)
import Control.Concurrent (forkIO)
import Control.Monad (void)

sleep :: Integer -> CreateProcess
sleep x = shell (printf "sleep %d; echo %d" x x)
-- sleep x = shell (printf "sleep %d, echo %d, touch %d.haskell" x x x)

main = foldr1 (>>) $ [
  forkIO $ void $ createProcess task |
  task <- [ sleep 1, sleep 2, sleep 3, sleep 4, sleep 5] ]

我做错了什么?

1 个答案:

答案 0 :(得分:0)

您必须呈现文件index.twig。 Twig不会搜索扩展你的基础的其他文件。

[...]
// The Homepage! (/)
    case '/':
        echo $twig->render('../../app/Resources/views/index.twig', array(
            'pageTitle' => 'Suit Up!',
        ));
        break;
[...]