statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
3.71k stars 508 forks source link

Blade global vars overridden by entry vars #6165

Closed stuartcusackie closed 8 months ago

stuartcusackie commented 2 years ago

Bug description

I have a global set called images and my entry has a field called images. When viewing an entry route I would access the global images as $images but in this case my entry's $images field is overriding it.

Perhaps it would be better if global variables were automatically passed to the view as: $global->images or $global_images Either that or remove all the individual entry field variables. It's better to access them under $page->fieldname in blade anyway.

For the moment I am going to manually prefix all of my global sets with global_ as a workaround.

How to reproduce

Set up a global set with the same name as an entries field and try to access the global set in blade.

Logs

No response

Versions

Statamic 3.3.12 Solo Laravel 9.14.1 PHP 8.1.1 spatie/statamic-responsive-images 2.12.3 stillat/relationships 1.0.2

Installation

Fresh statamic/statamic site via CLI

Antlers Parser

No response

Additional details

No response

duncanmcclean commented 8 months ago

I'm not sure there's much we can do about this. The same thing would happen if you're using Antlers - the variables will collide.

As you've mentioned, you can workaround this by adding a prefix to the handles of global sets.