Undefined var w/ sage @foreach, but not vanilla foreach()

The main issue is with filter wc_get_template. We cannot simply render the template, because the filter is used in get_theme_info() function and it expects file path, not the output. If the compiled template is included directly and not with Blade’s render function, there is not defined $__env variable, therefore we have to define this variable. I will try to find a way to recognise when the filter is called from get_theme_info function and when it’s used for rendering and try to implement different behaviour for those different situations.

Filter wc_get_template_part can render output directly because the result of the filter is used for render only. I will update the package to do that.

Filter template_include is processed by sage and there is render function used, so any template that goes through this filter works as expected.

There is some work that needs to be done. As a workaround we can use the following code in the blade templates:

@php
$__env = App\sage(‘blade’);
@endphp
2 Likes