Search

/views/vsearch/Results.html (1.2 KB)

 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
36
37
38
39
40
41
42
43
{% import (
"{{{ .Package }}}/app"
"{{{ .Package }}}/app/controller/cutil"
"{{{ .Package }}}/app/lib/search"
"{{{ .Package }}}/app/lib/search/result"
"{{{ .Package }}}/app/util"
"{{{ .Package }}}/views/layout"
) %}

{% code type Results struct {
layout.Basic
Params *search.Params
Results result.Results
Errors []error
} %}

{% func (p *Results) Body(as *app.State, ps *cutil.PageState) %}
<div class="card">
<h3>{% if p.Params.Q == "" %}Search{% else %}[{%s p.Params.Q %}] search results{% endif %}</h3>
<form class="mt expanded" action="{%s ps.SearchPath %}">
<input name="q" value="{%s p.Params.Q %}" />
<div class="mt"><button type="submit">Search Again</button></div>
</form>
</div>
{%- if p.Params.Q != "" && len(p.Results) == 0 -%}
<div class="card">
<h3>No results</h3>
</div>
{%- endif -%}
{%- for _, res := range p.Results -%}
{%= Result(res, p.Params, as, ps) %}
{%- endfor -%}
{% if len(p.Errors) > 0 %}
<div class="card">
<h3>{%s util.StringPlural(len(p.Errors), "Error") %}</h3>
<ul class="mt">
{%- for _, e := range p.Errors -%}
<li>{%s e.Error() %}</li>
{%- endfor -%}
</ul>
</div>
{% endif %}
{% endfunc %}