浏览代码

Add very basic promoted search results display

Thibaud Colas 1 年之前
父节点
当前提交
d686b7ddf6
共有 1 个文件被更改,包括 35 次插入2 次删除
  1. 35 2
      bakerydemo/templates/search/search_results.html

+ 35 - 2
bakerydemo/templates/search/search_results.html

@@ -1,5 +1,5 @@
 {% extends "base.html" %}
-{% load wagtailcore_tags wagtailimages_tags %}
+{% load wagtailcore_tags wagtailimages_tags wagtailsearchpromotions_tags %}
 
 {% block title %}Search{% if search_results %} results{% endif %}{% if search_query %} for “{{ search_query }}”{% endif %}{% endblock %}
 
@@ -39,7 +39,40 @@
                         {% endfor %}
                     </ul>
                 {% elif search_query %}
-                    <p class="search__introduction">No results found for “{{ search_query }}”.</p>
+                    {% get_search_promotions search_query as search_promotions %}
+                    {% if search_promotions %}
+                        <p class="search__introduction">You searched for “{{ search_query }}”, {{ search_promotions|length }} result{{ search_promotions|length|pluralize }} found.</p>
+                        <ul class="search__results">
+                            {% for search_promotion in search_promotions %}
+                                <li class="listing-card">
+                                    <a class="listing-card__link" href="{% pageurl search_promotion.page.specific %}">
+                                        {% if search_promotion.page.specific.image %}
+                                            <figure class="listing-card__image">
+                                                {% image search_promotion.page.specific.image fill-180x180-c100 loading="lazy" %}
+                                            </figure>
+                                        {% endif %}
+                                        <div class="listing-card__contents">
+                                            <h3 class="listing-card__title">{{ search_promotion.page.specific }}</h3>
+                                            <p class="listing-card__content-type">
+                                                {% if search_promotion.page.specific.content_type.model == "blogpage" %}
+                                                    Blog Post
+                                                {% elif search_promotion.page.specific.content_type.model == "locationpage" %}
+                                                    Location
+                                                {% else %}
+                                                    Bread
+                                                {% endif %}
+                                            </p>
+                                            <p class="listing-card__description">
+                                                {% if search_promotion.page.specific.search_description %}{{ search_promotion.page.specific.search_description|richtext }}{% endif %}
+                                            </p>
+                                        </div>
+                                    </a>
+                                </li>
+                            {% endfor %}
+                        </ul>
+                    {% else %}
+                        <p class="search__introduction">No results found for “{{ search_query }}”.</p>
+                    {% endif %}
                 {% else %}
                     <p class="search__introduction">You didn&apos;t search for anything!</p>
                 {% endif %}