Frustrating experience with Blade

Hi guys,

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:

// snip
    <section class="posts">
      @while (have_posts()) @php(the_post())
        @php
          global $post;
          echo $post->menu_order;
        @endphp
        @include('partials.content-'.get_post_type(),
        ['image' => $controller::getImage()])
      @endwhile
    </section>

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.

3 Likes

To be explicit, it’s this line that needs to be changed:

<section class="posts">
  @while (have_posts()) @php(the_post()) <--- right here!!
  ...

Changing it to this should fix your issue:

// snip
<section class="posts">
  @while (have_posts()) @php the_post() @endphp
  ...
5 Likes

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! :smile:

2 Likes

This topic was automatically closed after 42 days. New replies are no longer allowed.