Including PHP files in blade templates

Hi Guys,

Long time lurker, first time poster! Thanks for all the hardwork on sage, I have recently adopted it to modernise my wordpress workflow & it seems a treat to use.

One question I have is on my blade template, I have some inline that needs to call a php file in my /app/ folder. When I try __DIR__."/app/myfile.php the eror I get is that its looking in an acorn cache file:

Illuminate \ View \ ViewException (E_ERROR)
Failed opening required '/Users/me/dev/mysite/app/public/wp-content/cache/acorn/views/app/openai.php' (include_path='.:/usr/share/php:/www/wp-content/pear') (View: /Users/me/dev/mysite/app/public/wp-content/themes/austin_kemp/resources/views/page-ai.blade.php)

Any tips would be greatly appriciated!

Take it easy! :sunglasses:

So you want to include a PHP file inside a Blade-PHP template file?
You should use a function or a blade directive that itself includes the PHP.

Hi @strarsis,

Yeah thats right, I’ve been struggling with it below is the code. the code is in one of my template blade files, trying to call a php file in the /App/ Directory

Thanks for your answer, I’ll have a look at blade directives.

require_once __DIR__  "/app/openai.php";

That openapi.php directly results in output?
You can include it in a function and store its output from the PHP output buffer into a variable (and/or return it).

Apologies @strarsis still a bit new to Sage/Laravel Blade i’ll give that a go.

Thanks again for the help