Browse Source

index & base twig

twig
Ernest Debruyne 2 years ago
parent
commit
8ac8d562e6
4 changed files with 37 additions and 12 deletions
  1. 1
    0
      .gitignore
  2. 15
    12
      public/index.php
  3. 7
    0
      templates/base.html.twig
  4. 14
    0
      templates/index.html.twig

+ 1
- 0
.gitignore View File

@@ -1,2 +1,3 @@
vendor/
private/test.db
cache/

+ 15
- 12
public/index.php View File

@@ -16,9 +16,7 @@ require __DIR__ . '/../vendor/autoload.php';
$app = AppFactory::create();

$loader = new \Twig\Loader\FilesystemLoader('../templates');
$twig = new \Twig\Environment($loader, [
'cache' => '../cache',
]);
$twig = new \Twig\Environment($loader);

ini_set('display_errors', 'Off');

@@ -60,16 +58,21 @@ $app->get('/', function (Request $request, Response $response, array $args) {

init();
addNavbar($response);
$response->getBody()->write('<hr/><h1>Onze blog</h1>');
$response->getBody()->write('<ul>');
global $twig;
$template = $twig->load('index.html.twig');
$a = $template->render(["key" => "value", "key2" => ["val1", "val2", "val3"], "name" => "John", "lastname" => "Doe"]);
$response->getBody()->write($a);
// addNavbar($response);
// $response->getBody()->write('<hr/><h1>Onze blog</h1>');
// $response->getBody()->write('<ul>');
foreach ($_SESSION['blogs'] as $art) {
$response->getBody()->write('<li><a href="/blog/' . $art['slug'] . '">' . $art['title'] . '</a></li>');
}
$response->getBody()->write('</ul>');
$response->getBody()->write('<hr/>');
addFooter($response);
// foreach ($_SESSION['blogs'] as $art) {
// $response->getBody()->write('<li><a href="/blog/' . $art['slug'] . '">' . $art['title'] . '</a></li>');
// }
// $response->getBody()->write('</ul>');
// $response->getBody()->write('<hr/>');
// addFooter($response);


return $response;

+ 7
- 0
templates/base.html.twig View File

@@ -0,0 +1,7 @@
<html>
<body>
<div id="navbar">{% block navbar %} {% endblock %}</div>
<div id="main">{% block main %} {% endblock %}</div>
<div id="footer">{% block footer %} {% endblock %}</div>
</body>
</html>

+ 14
- 0
templates/index.html.twig View File

@@ -0,0 +1,14 @@
{% extends "base.html.twig" %} {% block main %}
<h1>
{% for key in key2 %}
<li>{{ key }}</li>
{% endfor %}
</h1>
{% block navbar %} {% endblock %}
<form action="/">
<label for="name">First Name</label>
<input type="text" name="name" value="{{ name }}" /><br />
<label for="last-name">Last Name</label>
<input type="text" name="last-name" value="{{ lastname }}" />
</form>
{% endblock %} {% block footer %} Dit is de footer {% endblock %}

Loading…
Cancel
Save