Kaynağa Gözat

navbar and body filled

Twig
Ruben De Baets 2 yıl önce
ebeveyn
işleme
1f4af78192
3 değiştirilmiş dosya ile 29 ekleme ve 33 silme
  1. 15
    12
      public/index.php
  2. 5
    12
      templates/index.html.twig
  3. 9
    9
      templates/navbar.html.twig

+ 15
- 12
public/index.php Dosyayı Görüntüle

@@ -17,25 +17,26 @@ require __DIR__ . '/../vendor/autoload.php';

$twig = new Twig('../templates');

addNavbar();

$app = AppFactory::create();



//$db = new DB();
ini_set('display_errors', 'Off');
function addNavbar($response)
function addNavbar()
{
global $twig;

$response->getBody()->write("<html><head></head><body>");
if (isset($_SESSION['username'])) {
$response->getBody()->write('<div><a href="/">Index</a> | <a href="/blog/create">Create Blog</a> | <a href="/logout">Logout</a></div>');
} else {
$response->getBody()->write('<div><a href="/">Index</a> | <a href="/login">Login</a></div>');
}
return;
$urls = [
["link" => "https://www.google.be", "name" => "Google"],
["link" => "https://www.facebook.com", "name" => "Facebook"],
["link" => "https://www.twiter.com", "name" => "Twitter"]
];
$twig->addBlockVariable('navbar', ['urls' => $urls]);
}



function addFooter($response)
{
$response->getBody()->write('<div>Privacy statement | Cookie Policy | Contact</div>');
@@ -60,7 +61,9 @@ $app->get('/', function (Request $request, Response $response, array $args) {
"key" => "value",
'key2' => ["val1", "val2", "val3"],
"key3" => ["x1" => "y1", "x2" => "y2"],
"loggedIn" => isset($_SESSION['username'])
"loggedIn" => isset($_SESSION['username']),
"content" => "Dit is de main body met info"

];

global $twig;

+ 5
- 12
templates/index.html.twig Dosyayı Görüntüle

@@ -1,15 +1,8 @@
{% extends "base.html.twig" %} {% block main %}
{% extends "base.html.twig" %}

<h1>{{ key }}</h1>

<hr />
<ul>
{% for key in key2 %}
<li>{{ key }}</li>
{% endfor %}
{% block main %}

{{
key3.x1
}}
</ul>
{% endblock %} {% block footer %} Dit is de footer{% endblock %}
{{ content }}

{% endblock %}

+ 9
- 9
templates/navbar.html.twig Dosyayı Görüntüle

@@ -1,9 +1,9 @@
<div><a href="/">Index</a> |
{% if loggedIn %}
<a href="/blog/create">Create Blog</a> |
<a href="/logout">Logout</a></div>
{% else %}
<a href="/login">Login</a></div>
{% endif %}
<div>
<ul>
{% for url in navbar.urls %}
<li>
<a href="{{ url.link }}">{{ url.name }} </a>
</li>
{% endfor %}
</ul>
</div>

Loading…
İptal
Kaydet