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

using {{? ?}} php tag, we cannot override existing variable. #11222

Open
dadaxr opened this issue Dec 6, 2024 · 3 comments
Open

using {{? ?}} php tag, we cannot override existing variable. #11222

dadaxr opened this issue Dec 6, 2024 · 3 comments
Labels

Comments

@dadaxr
Copy link
Contributor

dadaxr commented Dec 6, 2024

Bug description

In an antlers template creating a variable with a native php tag works fine :

{{? $newVar = "test"; ?}}
{{ newVar|dump }} {{# output "test" #}}

altering this newly created variable also works fine :

{{? $newVar = $newVar."_updated"; ?}}
{{ newVar|dump }} {{# output "test_updated" #}}

BUT, if the variable already exists in the cascade, we cannot alter it ...

For instance, if the "title" variable already exists in the cascade with the value "myTitle", it wont be updated...

{{? $title= "overridden title"; ?}}
{{ title|dump }} {{# still output "myTitle" instead of "overridden title" #}}

interestingly, if within the {{? ?}} tag itself, the override happens :

{{? $title= "overridden title"; dd($title}} ?}} {{# outputs "overriden title" #}}

note it's a project with statamic 3.4.11, but i'm pretty sure it also happens on the last versions...

How to reproduce

just use the above examples

Logs

No response

Environment

Environment
Application Name: Statamic leporc
Laravel Version: 9.52.7
PHP Version: 8.1.14
Composer Version: 2.5.1
Environment: local
Debug Mode: ENABLED
URL: leporc.localhost
Maintenance Mode: OFF

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

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

Statamic
Addons: 2
Antlers: runtime
Stache Watcher: Disabled
Static Caching: Disabled
Version: 3.4.11 PRO

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

@duncanmcclean
Copy link
Member

@JohnathonKoster Do you have any ideas about what's happening here?

@JohnathonKoster
Copy link
Contributor

JohnathonKoster commented Dec 6, 2024

@JohnathonKoster Do you have any ideas about what's happening here?

Its leveraging previous assignments inside Antlers, or entirely new variables created inside PHP in order to detect what should be pushed back up after executing the PHP code. This could be expanded to also include a "did variable change" check.

For example, if we had something like this, it would pick up on the change since title is available in its list of items to pay attention to (not saying this is the solution, just an example to help demonstrate):

{{ title = title /}}
{{? $title = 'a new title'; ?}}
{{ title /}}

@dadaxr
Copy link
Contributor Author

dadaxr commented Dec 9, 2024

From my point of view, having php tags able to manipulate the current context (and its existing variables) is a powerful feature. On the contrary, not beeing able to do it, seems counter intuitive (+ the fact it's not documented).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants