我使用XAMPP(v 3.2.1),Composer和Slim框架来学习PHP编程。还有什么打开" localhost //" Chrome中的页面,只显示文字。没有图形和CSS,但HTML正确和活动超链接。 还有" {%extends" main.twig" %} {%block content%}"在它的开头和" {%endblock content%}"到底。
在Twig模板化之前,项目正常运行:通过Slim进行页面路由并正确的HTML解释。
项目结构:
' ... / htdocs中/埃默森' - 主文件夹,
' /emerson/index.php' - 主要的php控制器(见本帖下面的代码),
' /emerson/templates/main.twig' - 主要的Twig模板(参见本文下面的代码),在文件夹' temlates'还有其他文字:' about.twig'和' contact.twig'
作曲:
{
"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>
请帮我解决这个问题!
答案 0 :(得分:0)
您只需使用{% endblock %}
而不是{% endblock content %}