-
-
Notifications
You must be signed in to change notification settings - Fork 596
Description
Bug description
One of my view contains country flags, as {{ emoji }} in the code.
Since Google Chrome does not support flags, I have code to show a flag unless the HTTP agent contains "Chrome" and "Windows" (and I will see if I need to adjust the condition later).
The condition is a little bit complex:
- To avoid too much repeat, I defined a variable
agentto contain the user agent. It can only be defined in a PHP block:{{? $agent = str($_SERVER['HTTP_USER_AGENT']); ?}} - The condition itself does not use further variables:
{{ unless { $agent | contains("Chrome") } && { $agent | contains("Windows") } }}
However, flags are always displayed.
With a bit more efforts into investigating, it seems the part that makes it fail is specifically the curly brackets (i.e. NOT the use of PHP to define $agent NOR the contains modifiers NOR the fact that $agent may not contain what I expect).
How to reproduce
Here is a very simplified example where I removed all the moving parts except the curly brackets. When you render it, you will see unless { one } returns true while:
if { one }also returns trueunless onereturn falseif !oneandif !{ one }both return false
{{ one = 1 }}
Test (with curly brackets):
<ul class="list-disc list-inside ml-4 mb-4">
<li>if { one }: {{ if { one } }}true{{ else }} false{{ /if }}</li>
<li>unless { one }: {{ unless { one } }}true{{ else }} false {{ /unless }}</li>
<li>if !{ one }: {{ if !{ one } }}true{{ else }} false{{ /if }}</li>
</ul>
Test (without curly brackets):
<ul class="list-disc list-inside ml-4 mb-4">
<li>if one: {{ if one }}true{{ else }} false{{ /if }}</li>
<li>unless one: {{ unless one }}true{{ else }} false {{ /unless }}</li>
<li>if !one: {{ if !one }}true{{ else }} false{{ /if }}</li>
</ul>
Logs
Environment
Environment
Application Name: GaiaMine UAT
Laravel Version: 11.45.2
PHP Version: 8.3.24
Composer Version: 2.8.6
Environment: local
Debug Mode: ENABLED
URL: design.test/
Maintenance Mode: OFF
Timezone: UTC
Locale: en
Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED
Drivers
Broadcasting: log
Cache: file
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: database
Pulse
Enabled: ENABLED
Version: v1.4.3
Livewire
Livewire: v3.6.4
Statamic
Addons: 5
Sites: 1
Stache Watcher: Enabled (auto)
Static Caching: Disabled
Version: 6.0.0-alpha.4 PRO
Statamic Addons
alt-design/alt-seo: 1.3.0
jacksleight/statamic-bard-mutator: 3.0.5
pecotamic/sitemap: 1.4.9
statamic/eloquent-driver: 4.30.2
stillat/antlers-components: 2.6.0
Statamic Eloquent Driver
Asset Containers: file
Assets: file
Blueprints: file
Collection Trees: file
Collections: file
Entries: eloquent
Fieldsets: file
Form Submissions: eloquent
Forms: file
Global Sets: file
Global Variables: file
Navigation Trees: file
Navigations: file
Revisions: file
Sites: file
Taxonomies: file
Terms: file
Tokens: fileInstallation
Fresh statamic/statamic site via CLI
Additional details
The issue exist in 5.x and 6.x.
I cannot be sure anymore so the following is to take with a grain of salt.
What I remember of the time when the view was originally developed (in 2024) is:
- the
agentvariable did not need to be defined using a PHP block. - the
unlesscondition was working, i.e. no emoji were displayed on Chrome.