ソースを参照

Ajout de la liste des tags

Sangfroid 1 ヶ月 前
コミット
68e43b4eb0

+ 16 - 0
src/Twig/ListeTags.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Twig;
+
+use Twig\Extension\AbstractExtension;
+use Twig\TwigFunction;
+
+class ListeTags extends AbstractExtension
+{
+    public function getFunctions(): array
+    {
+        return [
+            new TwigFunction('liste_tags', [ListeTagsRuntimeExtension::class, 'getListeTags'])
+        ];
+    }
+}

+ 21 - 0
src/Twig/ListeTagsRuntimeExtension.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace App\Twig;
+
+use App\Repository\TagRepository;
+use Twig\Extension\RuntimeExtensionInterface;
+
+class ListeTagsRuntimeExtension implements RuntimeExtensionInterface
+{
+    public function __construct(
+        protected readonly TagRepository $tagRepository
+    )
+    {
+        
+    }
+
+    public function getListeTags(): array
+    {
+        return $this->tagRepository->findAll();
+    }
+}

+ 9 - 0
templates/_aside.html.twig

@@ -41,6 +41,15 @@
         {% endif %}
     </section>    
     
+    {% set tags = liste_tags() %}
+    <section>
+        <h2>Etiquettes</h2>
+        <p>
+        {% for tag in tags %}
+            <a href="{{ path('app_search', {'tag': tag.name}) }}"><span class="tag">{{ tag }}</span></a>
+        {% endfor %}
+        </p>
+    </section>
     {#
     <!-- Catégories -->
     <section class="categories">