I try to render a blade template file manually in a function in the functions.php but i’m not achieving it. I already read this topic: How to render a blade template from filter function but the suggested tips did not help in my case.
I tried something like this: \App\template('ajax.form', ['param' => 'value']);
Basically I want to make an AJAX call from the frontend, then fill in some parameters into a blade template and return the rendered view.
Is this possible in a convenient way in Sage9 or is there another way to do this?
Ok. I do not know what has happened, but suddenly it works!
However, to provide some more infos on people trying to achieve the same thing:
I first got ‘Error 500’ with no output.
My current (working) setup looks like this:
The blade template is located in views/ajax/form.blade.php.
In my functions.php I echo the content like this: echo \App\template('ajax.form', ['var' => $variable]);
It works as expected: I have the $var in my template available. I still can not understand why it suddenly works and neither can I reproduce the error, but I’ll keep you updated as soon as the problem reoccurs.
With a 500 error, you should have more details in your web server’s error log… My guess is that there was a PHP error somewhere, possibly in your compiled Blade template (they get stored in your wp-content/uploads/cache folder). Maybe there was a delay in the compiled templates being updated.
That must be a bit frustrating… I haven’t encountered any issues with my setup (Laravel Valet) and I’m usually running yarn start with Browsersync so the page refreshes as soon as I update a Blade template.