I’ve written a couple of websites using Sage and, while it’s a great tool, the bizarre problems I’ve been having with blade is getting me down.
Here’s an example.
I have written the following logic:
@while (have_posts()) @php(the_post())
['image' => $controller::getImage()])
I iterated to this working point, and a few iterations ago it had errors - fair enough, but now that the code is actually fine, blade hasn’t caught up and insists there’s an error.
This is what I see, using the WHOOPS debugging tool:
This shows that blade is not catching up with the changes.
What do I have to do to get it to behave?
You need to add closing tags (i.e
@endphp) for all
@php directives now. I forget which version, but it was a change in Laravel.
To be explicit, it’s this line that needs to be changed:
@while (have_posts()) @php(the_post()) <--- right here!!
Changing it to this should fix your issue:
@while (have_posts()) @php the_post() @endphp
Thanks guys - it all makes sense now!
The inline bit
@php( ... ) seemed to work fine before I added the
@php ... @endphp bit underneath. Maybe it was loading from the blade cache, from a previous version of blade that knew how to parse it.
I was frustrated because I’d had similar things happen before where I “knew” the code was right but blade didn’t want to update its position on the matter, or would complain about an issue and then load fine on the next page reload - maybe a race condition in the webpack watcher.
Anyway, THANK YOU!
This topic was automatically closed after 42 days. New replies are no longer allowed.