summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2022-01-27 10:29:07 +0100
committerDaniel Weipert <code@drogueronin.de>2022-01-27 10:29:07 +0100
commit27a1680fe386db99fd983eba64533091b9451d27 (patch)
treecb0eb55fb281c9af492b587399f895400ea1c2da
parent10c86197f1f63e222dfc9e937911e35ab500a208 (diff)
Add layout to home route
-rw-r--r--src/Controller/Home.php6
-rw-r--r--src/Template.php7
-rw-r--r--templates/home.twig28
-rw-r--r--templates/root.twig8
4 files changed, 33 insertions, 16 deletions
diff --git a/src/Controller/Home.php b/src/Controller/Home.php
index 36879e0..ecc209e 100644
--- a/src/Controller/Home.php
+++ b/src/Controller/Home.php
@@ -11,13 +11,12 @@ class Home
public static function index()
{
$c = DB::$entityManager->getRepository(Card::class)->findOneBy([], ['id' => 'DESC']);
- echo "<pre>";
- $c && var_dump(
+ $debug = $c ? [
array_map(fn ($item) => [$item->key, $item->value], $c->meta->toArray()),
array_map(fn ($item) => "<img style='max-width: 100%;max-height:300px;' src='$item->path'> Votes: " . $item->getVotesTotal(), $c->artworks->toArray()),
array_map(fn ($item) => $item->value, $c->votes->toArray()),
'Votes: ' . $c->getVotesTotal(),
- );
+ ] : null;
return Template::render('home.twig', [
'fields' => [
@@ -25,6 +24,7 @@ class Home
'converted mana cost' => 'meta[cmc]',
'is uno reverse' => 'meta[is_uno_reverse]',
],
+ 'debug' => $debug,
]);
}
diff --git a/src/Template.php b/src/Template.php
index b4360b8..9c0b0d6 100644
--- a/src/Template.php
+++ b/src/Template.php
@@ -3,6 +3,7 @@
namespace Elements;
use Twig\Environment;
+use Twig\Extension\DebugExtension;
use Twig\Loader\FilesystemLoader;
class Template
@@ -12,7 +13,11 @@ class Template
public static function init(): void
{
$loader = new FilesystemLoader(dirname(__DIR__) . '/templates');
- self::$twig = new Environment($loader);
+ self::$twig = new Environment($loader, [
+ 'debug' => true,
+ ]);
+
+ self::$twig->addExtension(new DebugExtension());
}
public static function render(string $name, array $context = []): string
diff --git a/templates/home.twig b/templates/home.twig
index d4e86ed..47aebde 100644
--- a/templates/home.twig
+++ b/templates/home.twig
@@ -1,14 +1,24 @@
+{% extends 'base.twig' %}
+
+{% block main %}
<h3>Home</h3>
-<form action="/card/add" method="post" enctype="multipart/form-data">
- {% for key, field in fields %}
+<pre>
+{{ dump(debug) }}
+</pre>
+
+<section class="content">
+ <form action="/card/add" method="post" enctype="multipart/form-data">
+ {% for key, field in fields %}
+ <label>
+ {{ key }} <input type="text" name="{{ field }}">
+ </label>
+ {% endfor %}
<label>
- {{ key }} <input type="text" name="{{ field }}">
+ Image <input type="file" name="images[]" multiple>
</label>
- {% endfor %}
- <label>
- Image <input type="file" name="images[]" multiple>
- </label>
- <input type="submit" value="Hinzufügen">
-</form>
+ <input type="submit" value="Hinzufügen">
+ </form>
+</section>
+{% endblock %}
diff --git a/templates/root.twig b/templates/root.twig
index 8be64dd..b901ffb 100644
--- a/templates/root.twig
+++ b/templates/root.twig
@@ -1,11 +1,13 @@
-<html> <link rel="/favicon.ico" href="#">
-
+<!doctype html>
+<html>
<head>
<title>Elements</title>
+ <link rel="icon" href="/favicon.ico">
{% block css %}{% endblock %}
</head>
<body>
{% block body %}{% endblock %}
{% block js %}{% endblock %}
</body>
-</html> \ No newline at end of file
+</html>
+