statamic / ideas

💡Discussions on ideas and feature requests for Statamic
https://statamic.dev
30 stars 1 forks source link

empty() returns true on lazy loaded fields abstracted by Statamic/Fields/Values class in Blade #1020

Open Dimchao opened 11 months ago

Dimchao commented 11 months ago

When conditionally setting title fields, etc. based on field values of objects passed into templates, the empty function will return false on a field that exists and is accessible via: $data->my_field_data

Example: `

@if(false === empty($data->my_field_data))
    <h1>{{ $data->my_field_data }}</h1>
@endif

`

Solution Adding the below code into the Statamic/Fields/Values class makes the above example work as expected: public function __isset($key){ return $this->getProxiedInstance()->has($key); }

I don't know how to run tests per the recommendations for doing a pull request and adding this code into the base. Would love it if it was added.