Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional {{ no_results }} tags revert to the value of the first instance of the tag #11218

Closed
finnjsmith opened this issue Dec 4, 2024 · 0 comments · Fixed by #11234
Closed

Comments

@finnjsmith
Copy link

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:

{{ search:results index="{{ site:handle }}" paginate="6" as="results" }}
    <div class="...">
        <div class="...">
            <div class="...">
                <!-- 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
                                <a
                                    href="/contact"
                                    class="..."
                                >
                                    contact our team.
                                </a>
                            </p>
                        {{ else }}
                            <div class="...">
                                {{ partial src="sets/single_column" }}
                            </div>
                        {{ /if }}
                    {{ /collection:functional_pages }}
                {{ else }}
                    ...

Logs

No response

Environment

Environment
Application Name: Redacted Project Name
Laravel Version: 11.34.0
PHP Version: 8.3.14
Composer Version: 2.7.7
Environment: local
Debug Mode: ENABLED
URL: project.international.local
Maintenance Mode: OFF
Timezone: UTC
Locale: en

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: null
Cache: file
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file

Statamic
Addons: 4
Sites: 13 (International, Australia, Belgium, and 10 more)
Stache Watcher: Enabled
Static Caching: Disabled
Version: 5.39.0 PRO

Statamic Addons
anakadote/statamic-recaptcha: 1.0.16
rias/statamic-redirect: 3.8.2
statamic/eloquent-driver: 4.18.0
transformstudios/review: 5.0

Statamic Eloquent Driver
Asset Containers: file
Assets: file
Blueprints: file
Collection Trees: eloquent
Collections: file
Entries: eloquent
Forms: eloquent
Global Sets: file
Global Variables: eloquent
Navigation Trees: file
Navigations: file
Revisions: eloquent
Sites: file
Taxonomies: file
Terms: eloquent
Tokens: file

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.

<!-- 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 }}
        ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants