Closed aerni closed 1 year ago
I haven't tried it with Antlers yet 🤷♂️
Does it simply not work? Are you getting any error message?
In Blade you would access a computed property like this {{ $this->post->title }}
. There's no way to access $this
in Antlers.
I’ve solved it by explicitly passing the data in the render method like this:
public function render()
{
return view('livewire.template', [
'property' => $this->property,
]);
}
Computed properties are not supported at the moment.
Hopefully the workaround from @mkriegeskorte does help.
Just wanted to note here that the workaround here works in Livewire 3.
Are computed properties in v3 not accessable like normal properties? Wondering if the workaround is needed.
They still require the $this->propertyname.
Must use $this in your template
Unlike normal properties, computed properties aren't directly available inside your component's template. Instead, you must access them on the $this object. For example, a computed property named posts() must be accessed via $this->posts inside your template.
Are computed properties in v3 not accessable like normal properties? Wondering if the workaround is needed.
They still require the $this->propertyname.
Must use $this in your template Unlike normal properties, computed properties aren't directly available inside your component's template. Instead, you must access them on the $this object. For example, a computed property named posts() must be accessed via $this->posts inside your template.
You are right.
You could probably use Antlers' PHP functionality to make it work like {{? $this->property ?}}
.
You could probably use Antlers' PHP functionality to make it work like
{{? $this->property ?}}
.
FYI: Looks like that does not work. $this
refers to Antlers NodeProcessor
.
Call to undefined method Statamic\View\Antlers\Language\Runtime\NodeProcessor::posts()
Is there a way to use computed properties with Antlers? https://laravel-livewire.com/docs/2.x/properties#computed-properties