You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've was using a search tag, and if there are no results, grabs an entry from a collection that templates the no search results layout. I wanted a fallback for if a "no_search_results" blueprint entry doesn't exist in my collection (just a small hardcoded line of text). I noticed that if I use {{ no_results }} for searching the collection for an entry, it always returns false and returns the fallback code, even if there is a valid entry in the collection. This is because the collection's no_results tag is always equal to the search tag's no_results value.
How to reproduce
Inside of a search tag, use a collection tag, and use the no results tag to try and change templated output based on the number of entries returned by the collection. You will find that the value no_results tag in the collection never changes.
Here's the code snippet that caused the issue for me:
{{ search:results index="{{ site:handle }}" paginate="6" as="results" }}
<divclass="..."><divclass="..."><divclass="..."><!-- NO RESULTS TAG NO. 1 -->
{{ if no_results }}
{{ collection:functional_pages blueprint:is="no_search_results" limit="1" }}
<!-- I've done a sanity check and there is definitely an entry --><!-- NO RESULTS TAG NO. 2, always returning false as "no results tag no 1" is false -->
{{ if no_results }}
<p>
Sorry, no results were found for this term. If you can't find what you are looking for,
please
<ahref="/contact"
class="..."
>
contact our team.
</a></p>
{{ else }}
<divclass="...">
{{ partial src="sets/single_column" }}
</div>
{{ /if }}
{{ /collection:functional_pages }}
{{ else }}
...
I was able to get the desired functionality with this workaround, however I still thought I should report the bug.
<!-- if no search results -->
{{ if no_results }}
{{ collection:functional_pages blueprint:is="no_search_results" limit="1" }}
<!-- if no collection results -->
{{ if total_results <1}}...{{else}}....{{ /if }}
...
The text was updated successfully, but these errors were encountered:
Bug description
I've was using a search tag, and if there are no results, grabs an entry from a collection that templates the no search results layout. I wanted a fallback for if a "no_search_results" blueprint entry doesn't exist in my collection (just a small hardcoded line of text). I noticed that if I use {{ no_results }} for searching the collection for an entry, it always returns false and returns the fallback code, even if there is a valid entry in the collection. This is because the collection's no_results tag is always equal to the search tag's no_results value.
How to reproduce
Inside of a search tag, use a collection tag, and use the no results tag to try and change templated output based on the number of entries returned by the collection. You will find that the value no_results tag in the collection never changes.
Here's the code snippet that caused the issue for me:
Logs
No response
Environment
Installation
Fresh statamic/statamic site via CLI
Additional details
I was able to get the desired functionality with this workaround, however I still thought I should report the bug.
The text was updated successfully, but these errors were encountered: