Ernest Debruyne 2 роки тому
джерело
коміт
16fc98e4cf
2 змінених файлів з 14 додано та 5 видалено
  1. 7
    4
      public/index.php
  2. 7
    1
      src/View/Twig.php

+ 7
- 4
public/index.php Переглянути файл

@@ -22,17 +22,19 @@ $app = AppFactory::create();

ini_set('display_errors', 'Off');

function addNavbar($response)
function addNavbar()
{
global $twig;

$urls = [
["link" => "https://www.google.be", "name" => "Google"],
["link" => "https://www.facebook.com", "name" => "Facebook"],
["link" => "https://www.twitter.com", "name" => "Twitter"],
["link" => "https://www.twitter.com", "name" => "Twitter"]
];
$twig->addBlockVariable('navbar', ['urls' => $urls]);

$err = ['type' => 'notice', 'text' => 'We did it!'];
$twig->addBlockVariable('navbar', ['urls' => $urls]);
$twig->addBlockVariable('messages',$err);
}

function addFooter($response)
@@ -60,7 +62,7 @@ $app->get('/', function (Request $request, Response $response, array $args) {


init();
addNavbar();
global $twig;
$vars = [
"key" => "value",
@@ -71,6 +73,7 @@ $app->get('/', function (Request $request, Response $response, array $args) {

];
$err = ["type" => "error", "text" => "something's wrong"];
$a = $twig->render('index.html.twig', $vars);
$response->getBody()->write($a);


+ 7
- 1
src/View/Twig.php Переглянути файл

@@ -20,10 +20,16 @@ class Twig {
return $this->twig->load($tmpl);
}

public function addMessage($msg) {
$current = $this->variables['messages']['msgs'];
$current[] = $msg;
$this->variables['messages']['msgs'] = $current;
}

public function addBlockVariable($block, $data) {
$current = $this->variables[$block];
$new = array_merge($current, $data);
$this->variables = $new;
$this->variables[$block] = $new;
}

public function render($tmpl, $vars) {

Завантаження…
Відмінити
Зберегти