-
-
Save timkelty/6996339 to your computer and use it in GitHub Desktop.
{!-- Load view/model --} | |
{stash:embed:models:page} | |
{exp:low_search:results query="{segment_3}"} | |
{exp:stash:set_value name="total_results" value="{total_results}"} | |
{if no_results} | |
{exp:stash:set_value name="total_results" value="0"} | |
{/if} | |
{exp:switchee | |
variable="{channel_short_name}" | |
parse="inward" | |
} | |
{case value="product"} | |
{exp:stash:append_list name="product"} | |
{stash:embed:models:card | |
stash:channel="product" | |
process="start" | |
} | |
{/exp:stash:append_list} | |
{/case} | |
{case value="resource"} | |
{exp:stash:append_list | |
name="resource" | |
parse_tags="yes" | |
} | |
{stash:title}{title}{/stash:title} | |
{stash:entry_id}{entry_id}{/stash:entry_id} | |
{stash:cat_ids}{categories show_group="2"}{category_id}|{/categories}{/stash:cat_ids} | |
{exp:stash:set_list | |
name="files" | |
context="{entry_id}" | |
} | |
{cf_resource_file} | |
{stash:title}{title}{/stash:title} | |
{stash:extension}{extension}{/stash:extension} | |
{stash:url}{url}{/stash:url} | |
{/cf_resource_file} | |
{/exp:stash:set_list} | |
{/exp:stash:append_list} | |
{/case} | |
{case value="gallery"} | |
{exp:stash:append_list | |
name="gallery" | |
} | |
{stash:html} | |
<a href="{page_uri}"> | |
{exp:ce_img:single | |
src="{cf_gallery_img}" | |
width="133" | |
height="125" | |
crop="yes" | |
fallback_src="/assets/img/placeholder-1000x1000.png" | |
} | |
</a> | |
{/stash:html} | |
{/exp:stash:append_list} | |
{/case} | |
{case value="video"} | |
{exp:stash:append_list | |
name="video" | |
parse_tags="yes" | |
} | |
{stash:embed:models:video process="start"} | |
{/exp:stash:append_list} | |
{/case} | |
{case default="yes"} | |
{exp:stash:append_list name="other"} | |
{stash:title}{title}{/stash:title} | |
{stash:page_uri}{page_uri}{/stash:page_uri} | |
{/exp:stash:append_list} | |
{/case} | |
{/exp:switchee} | |
{/exp:low_search:results} | |
{exp:stash:set_list | |
name="resource_cats" | |
parse_tags="yes" | |
} | |
{!-- entry_id param is not working…can't get the list to parse first --} | |
{exp:gwcode_categories | |
group_id="2" | |
style="linear" | |
show_empty="no" | |
parse="inward" | |
entry_id='{exp:stash:get_list name="resource" backspace="1"}{entry_id}|{/exp:stash:get_list}' | |
} | |
{stash:cat_name}{cat_name}{/stash:cat_name} | |
{stash:cat_id}{cat_id}{/stash:cat_id} | |
{/exp:gwcode_categories} | |
{/exp:stash:set_list} | |
{!-- Page Content --} | |
{exp:stash:page:heading}Search Results for "{exp:low_search:keywords query="{segment_3}"}"{/exp:stash:page:heading} | |
{exp:stash:page:content} | |
{exp:stash:parse process="end"} | |
<div class="Grid Grid--2to1"> | |
<div class="Grid-cell Grid-cell--1"> | |
{if "{exp:stash:total_results}" == "0"} | |
<p>No results found.</p> | |
{/if} | |
{if {exp:stash:not_empty name="product"}} | |
<h2>Products</h2> | |
<div class="Grid Grid--3col"> | |
{exp:stash:get_list name="product"} | |
<div class="Grid-cell"> | |
{stash:embed:partials:card process="start"} | |
</div> | |
{/exp:stash:get_list} | |
</div> | |
{/if} | |
{if {exp:stash:not_empty name="video"}} | |
<h2>Videos</h2> | |
<div class="Grid Grid--3col"> | |
{exp:stash:get_list name="video"} | |
<div class="Grid-cell"> | |
{stash:embed:partials:video | |
process="start" | |
stash:desc="no" | |
} | |
</div> | |
{/exp:stash:get_list} | |
</div> | |
{/if} | |
{if {exp:stash:not_empty name="gallery"}} | |
<h2>Gallery of Ideas & Inspiration</h2> | |
<div class="Grid Grid--4col"> | |
{exp:stash:get_list name="gallery"} | |
<div class="Grid-cell"> | |
<div class="u-marginBm"> | |
{html} | |
</div> | |
</div> | |
{/exp:stash:get_list} | |
</div> | |
{/if} | |
</div> | |
<div class="Grid-cell Grid-cell--2"> | |
{if {exp:stash:not_empty name="resource"}} | |
<h2>Technical Resources</h2> | |
{exp:stash:get_list name="resource_cats"} | |
<h4>{cat_name}</h4> | |
<ul class="NoBullets"> | |
{exp:stash:get_list:resource | |
name="resource" | |
prefix="resource" | |
match="#{cat_id}\|#" | |
against="cat_ids" | |
} | |
{!-- {if resource:count == "1"}<h4>{cat_name}</h4><ul class="NoBullets">{/if} --} | |
<li> | |
{stash:embed:partials:files_by_resource process="start"} | |
</li> | |
{!-- {if resource:count == resource:total_results}</ul>{/if} --} | |
{/exp:stash:get_list:resource} | |
</ul> | |
{/exp:stash:get_list} | |
{exp:stash:get_list | |
name="resource" | |
prefix="resource" | |
match="#^$#" | |
against="cat_ids" | |
} | |
{if resource:count == "1"}<h4>Other</h4><ul class="NoBullets">{/if} | |
<li>{stash:embed:partials:files_by_resource process="start"}</li> | |
{if resource:count == resource:total_results}</ul>{/if} | |
{/exp:stash:get_list} | |
{/if} | |
{if {exp:stash:not_empty name="other"}} | |
<h2>News & Other Content</h2> | |
<ul> | |
{exp:stash:get_list name="other"} | |
<li><a href="{page_uri}">{title}</a></li> | |
{/exp:stash:get_list} | |
</ul> | |
{/if} | |
</div> | |
</div> | |
{/exp:stash:parse} | |
{/exp:stash:page:content} |
By far the most complicated Stash-ified template I've dealt with thus far. Previously, I would have thrown all the results into a big php array, and sorted and filtered from there.
The one part I didn't like about this implementation was storing the resource's categories as a pipe delimted string (line 31) and then calling the list and filtering it by that column (line 149). In php, I would just store the category ids as a nested array of each resource, and then get resourses where current cat in_array($cat, $resources['cats']) or something…In this case I didn't know how to filter my resource list by another list.
I could have just built up several resources lists, either named or context'ed by category, but then dealing with uncategorized resources (line 176) seemed troublesome.
I had a very similar problem just a few days ago actually when attempting to use search:field="{exp:stash:piped-ids}"
.
I tried loads of different things trying to get it to work. In the end I moved my two sections into separate stash embeds with process="start"
and shifted them to the top of the template to ensure the first one gets parsed before the second. (In your case the two chunks to be moved into embeds would be 1: your whole low_search:results tag, and 2: line 81-96.)
I also built the piped list directly with a simple append
tag, then fetched it in the second embed with a simple entry_id="dummy-{stash:piped-ids}"
to avoid the backspace inconvenience.
Make sense? In your case it may be worth just building a plugin, since this template is arguably getting more complicated than a chunk of php arrays...!
These are my two Stash embeds:
1: https://gist.github.com/thisisjamessmith/18d85e978b714aaf2eef
2: https://gist.github.com/thisisjamessmith/6a1b4446d2097958939c
Then in the main template:
{stash:embed:the-first process="start"}
{stash:embed:the-second process="start"}
Can't figure out why the entry_id param value on line 91 wont parse before the parent tag, even with parse="inward".
The purpose is to filter out categories that don't have any entries from the results. That way we don't have empty categories when we call on line 146. The commented out lines below that solve the display problem, but I couldn't figure out why it wasn't working.