Sage 9, wp_ajax, and nested Blade templates

I have a nested template structure like this:

template.blade.php > loop.blade.php > content.post_type.blade.php > partial.blade.php

This works well on initial page load. However, when I use wp_ajax to include the loop partial (include \App\template_path(locate_template('views/partials/loop'));), The nested includes are causing a 500 error. If I comment out the 2 nested includes, the ajax function works as expected. I’m guessing that there may be an issue with the included file paths, but I’m not familiar enough with Blade to know how to debug this.

Any help greatly appreciated!

Edit: After initiating the ajax request the error thrown is Undefined variable: __env, coming from the Compiled View Path in the cache directory, which seems to be related to the illuminate package.

Update: I can get everything working by switching the nested partials to php files and including them like so:

@php(include get_template_directory() . '/views/includes/ama-vote-count.php')

Kind of defeats the point of using Blade in the first place though…

1 Like

I’m on my phone so don’t take it for granted but I think you have to echo the template and not include

1 Like
echo \App\template(locate_template('views/partials/loop'));
2 Likes

Bump.

This is still an issue with Sage 9. I can use this fix to output more template parts, but then if those parts contain any Blade logic they fail.

The reply above you has the answer

:roll_eyes: …don’t mind me

1 Like