jonassiewertsen / statamic-livewire

A Laravel Livewire integration for Statamics antlers engine
85 stars 15 forks source link

Entangle in Antlers throws Invalid or unexpected token in console #7

Closed johncarter- closed 3 years ago

johncarter- commented 3 years ago

Hey Jonas

Thanks again for this package. I have discovered an issue:

I guess this due to the use of @ in the template and it breaks something in Antlers, although I'm not sharp enough to know exactly what.

I have made a demo repo that you can clone to see the issue in real life: https://github.com/johncarter-/statamic-antlers-livewire-entangle-error

Sorry I can't fix it.

jonassiewertsen commented 3 years ago

Thanks for your feedback and the repo.

I will take a look at it when I have a little extra time. Does the same error not appear if using Blade?

johncarter- commented 3 years ago

Not at the time I dont think. You can use either component from here https://github.com/johncarter-/statamic-antlers-livewire-entangle-error/tree/main/resources/views/livewire

jonassiewertsen commented 3 years ago

I can confirm this issue only happening with Antlers.

Screenshot 2021-01-03 at 14 42 11

Antlers does output the HTML correctly, but does use the @ to prevent parsing. Not sure if this is causing any problem? https://statamic.dev/antlers#prevent-parsing

Not sure why this error does appear. Do you have any idea @jasonvarga ?

jasonvarga commented 3 years ago

@entangle is a Blade directive. It does whatever it needs to do on the server side.

If you use Antlers, @entangle is going to make it all the way into the DOM and won't do whatever it is Livewire is expecting it to do.

This has nothing to do with the 'prevent parsing' feature of Antlers. That's only for when you're putting the @ before curly braces, like @{{ foo }}.

You'll need to make an Antlers equivalent of the directive. Maybe something like {{ livewire:entangle property="showDropdown" }}

<div x-data="{open: {{ livewire:entangle property="showDropdown" }})}">
jonassiewertsen commented 3 years ago

Thanks @jasonvarga

jonassiewertsen commented 3 years ago

This should be resolved with the last release v2.4.0

Can you confirm this @johncarter- ?