Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace single line PHP statements #3141

Closed
marcbelletre opened this issue Aug 4, 2023 · 1 comment
Closed

Replace single line PHP statements #3141

marcbelletre opened this issue Aug 4, 2023 · 1 comment

Comments

@marcbelletre
Copy link

Summary

I noticed a bug in Laravel that happens when using a single line @php directive followed by a @endphp tag anywhere in the template file. I created an issue on the laravel/framework repository but I was told it is a know issue for quite a while and there is no plan to fix it.

Because the default template files of Sage are using this syntax, it is impossible to use raw PHP inside the loop.

For example this would throw a compilation exception:

@extends('layouts.app')

@section('content')
  @while(have_posts()) @php(the_post())
    ...

    @php
    $var = 'something';
    @endphp 

    ...
  @endwhile
@endsection

I would suggest to update the default template files with the multiline syntax so it doesn't happen. The short syntax is easier to read but at least the full one compiles correctly :)

@extends('layouts.app')

@section('content')
  @while(have_posts()) 
    @php the_post() @endphp
  @endwhile
@endsection

I also suggested to the Laravel team to add a warning to the docs about this.

Additional context

No response

@Log1x
Copy link
Member

Log1x commented Jan 2, 2024

https://discourse.roots.io/t/blade-php-endphp-why-is-it-not-working/23713/11 has more context on this.

I understand that not everyone agrees, but this won't be getting changed in Sage's out of the box views unless it were to stop working all together.

@Log1x Log1x closed this as not planned Won't fix, can't repro, duplicate, stale Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants