dsrruefh12970 2015-11-10 09:04
浏览 63

使用XAMPP时使用Twig标记解释(使用Composer / Slim框架)

I'm using XAMPP (v 3.2.1), Composer and Slim framework for learning PHP programming. And somewhy when opening "localhost//" page in Chrome, just text appearing. Without graphic and CSS, but with HTML justifying and active hyperlink. Also there are "{% extends "main.twig" %} {% block content %}" on the begining of it and "{% endblock content %}" in the end.

Before Twig templating, project was runnig normally: with page routing through Slim and correct HTML interpreting.

Project structure:

'.../htdocs/emerson' - main folder,

'/emerson/index.php' - main php controller (see code down this post),

'/emerson/templates/main.twig' - main Twig template (see code down this post), in folder 'temlates' there are other teml.: 'about.twig' and 'contact.twig'

Composer:

{
"name": "yarkopol/first-proj",
"description": "My first Composer proj",
"authors": [
    {
        "name": "Jarko",
        "email": "yarko@dot.com"
    }
],
"require": {
    "monolog/monolog": "^1.17",
    "slim/slim": "^2.6",
    "twig/twig": "^1.22"
}
}

index.php

<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php 

require '/vendor/autoload.php';
date_default_timezone_set('Europe/Warsaw');

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$log = new Logger('name');
$log->pushHandler(new StreamHandler('app.log', Logger::WARNING));
$log->addWarning('Foo');

$app = new \Slim\Slim();

$app->get('/', function() use($app){
    $app->render('about.html');
});

$app->get('/contact', function() use($app){
    $app->render('contact.html');
});

$app->run();

?>

</body>
</html>

main.twig

<!doctype html>

<html lang="en">
<head>
    {% block head %}
      <meta charset="utf-8">
      <title>{% block title %}Ralph Waldo Emerson{% endblock title %}</title>
      <meta name="description" content="Ralph Waldo Emerson">
      <meta name="author" content="Treehouse">
      <link href='http://fonts.googleapis.com/css?family=Roboto:400,700' rel='stylesheet' type='text/css'>
      <link rel="stylesheet" href="css/master.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
      <script src="js/global.js"></script>
    {% endblock %}
</head>

<body>
  <header>
    <h1>Ralph Waldo Emerson</h1>
    <nav>
      <a href="index.html" class="selected">About</a>
      <a href="contact.html">Contact</a>
    </nav>
  </header>

  <div class="emerson">
    {% block hero %}<img src="images/emerson.jpg" alt="Picture of Ralph Waldo Emerson">{% endblock hero %}
  </div>

  <main>
    {% block content %}
    {% endblock content %}
  </main>

  <footer>
    {% block footer %}
        <p>A project from <strong><a href="http://teamtreehouse.com">Treehouse</a></strong></p>
        <nav>
          <a href="index.html" class="selected">About</a>
          <a href="contact.html">Contact</a>
        </nav>
    {% endblock footer %}
  </footer>

</body>
</html>

Please help me with this issue!

  • 写回答

1条回答 默认 最新

  • douying0108 2015-11-12 20:01
    关注

    You need to just use {% endblock %} not {% endblock content %}

    评论

报告相同问题?

悬赏问题

  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?