forked from SymfonyCasts/symfony-ux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchpreview-create-ajax-endpoint.diff
35 lines (34 loc) · 1.23 KB
/
searchpreview-create-ajax-endpoint.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
diff --git a/src/Controller/ProductController.php b/src/Controller/ProductController.php
index 84fe4c3..484d46a 100644
--- a/src/Controller/ProductController.php
+++ b/src/Controller/ProductController.php
@@ -26,6 +26,12 @@ class ProductController extends AbstractController
$searchTerm
);
+ if ($request->query->get('preview')) {
+ return $this->render('product/_searchPreview.html.twig', [
+ 'products' => $products,
+ ]);
+ }
+
return $this->render('product/index.html.twig', [
'currentCategory' => $category,
'categories' => $categoryRepository->findAll(),
diff --git a/templates/product/_searchPreview.html.twig b/templates/product/_searchPreview.html.twig
new file mode 100644
index 0000000..131e1b6
--- /dev/null
+++ b/templates/product/_searchPreview.html.twig
@@ -0,0 +1,12 @@
+<div class="list-group">
+ {% for product in products %}
+ <a
+ class="list-group-item list-group-item-action"
+ href="{{ path('app_product', { id: product.id }) }}"
+ >
+ {{ product.name }}
+ </a>
+ {% else %}
+ <div class="list-group-item">No results found!</div>
+ {% endfor %}
+</div>