Blade @php @endphp - why is it not working

@EHLOVader is correct, you must use either @php() or @php @endphp - you can not mix them.

I’m to blame for the use of @php() instead of @php @endphp in Sage’s default templating. My reasoning is/was:

  • We have to do a ton of 1-liners for WordPress stuff.
  • Composer’s provide an extremely powerful way in Sage/Acorn to handle all of your logic. Not even Laravel out of the box has the raw power of Acorn’s composer implementation without implementing it yourself. You can attach to literally every view on the fly.

I’ve written massive sites on Sage 10 at this point and have NEVER reached for @php in my views. The only time I could see it necessary is if you were bringing over another plugin’s view with a ton of logic inside of it, and in that case, you can simply use @php @endphp as needed (or even keep it raw PHP).

2 Likes