# Sage 9, wp_ajax, and nested Blade templates

**URL:** https://discourse.roots.io/t/sage-9-wp-ajax-and-nested-blade-templates/10456
**Category:** sage
**Created:** 2017-09-18T18:36:28Z
**Posts:** 7

## Post 1 by @nboliver — 2017-09-18T18:36:28Z

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.

---

## Post 2 by @nboliver — 2017-09-19T15:50:52Z

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…

---

## Post 3 by @Nicolo_Sacchi — 2017-09-19T22:59:24Z

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

---

## Post 4 by @Log1x — 2017-09-20T00:05:07Z

```
echo \App\template(locate_template('views/partials/loop'));
```

---

## Post 5 by @Simeon — 2018-06-22T01:19:17Z

> [@nboliver](#):
>
> 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…

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.

---

## Post 6 by @ben — 2018-06-22T01:35:46Z

The reply above you has the answer

---

## Post 7 by @Simeon — 2018-06-22T01:46:28Z

:roll_eyes: …don’t mind me
