I want to use the Custom Archives plugin in combination with Sage 9. But the plugin isn’t functioning with Sage 9, because it seems like it can’t find the right (blade) template.
Sage 9 echo’s the template rather than return it.
So my thinking is that you can use the filter on this line:
maybe something like:
add_filter('pre_custom_archive_template', function (string $template): void {
// This gets the Controller variables for your template.
$data = collect(get_body_class())->reduce(function ($data, $class) use ($template) {
return apply_filters("sage/template/{$class}/data", $data, $template);
}, []);
// Now echo the template with our Controller data passed to the template.
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo template($template, $data);
// We return an empty PHP file so that nothing extra is output by the plugin.
return get_stylesheet_directory() . '/index.php';
});
I haven’t tested it but this is usually what to do for most situations like this.
Thanks, using the the filter didn’t work. I got i working with:
...
// Fallback if no template given.
if ( '' == $template || false === $template || 'default' == $template ) {
// This gets the Controller variables for your template.
$data = collect(get_body_class())->reduce(function ($data, $class) use ($template) {
global $post_type;
$data['query'] = new \WP_Query( array(
'post_type' => $post_type,
) );
return apply_filters("sage/template/{$class}/data", $data, $template);
}, []);
$template = \App\template(locate_template(array_map(function($template) use ($post_type) {
return sprintf($template, $post_type);
}, array(
'views/archive-%s.blade.php',
'views/page-archive-%s.blade.php',
'views/page.blade.php',
'views/index.blade.php',
))), $data);
}
// Now echo the template with our Controller data passed to the template.
echo $template;
// We return an empty PHP file so that nothing extra is output by the plugin.
return get_stylesheet_directory() . '/index.php';
...