Roots Discourse

Use sober/controller from within a filter/action handler function

I use echo \App\template(...) to render some blade templates inside filter/action handlers.
How can these templates access the variables provided by the (sober/)controller?
Can I at least call the controller function myself and pass the variables to the template?
This would make things much easier for me.

Are you using Sage 9? If so try this:

$template = '/partials/name-of-your-template.blade.php';
$data = collect(get_body_class())->reduce(function ($data, $class) use ($template) {
    return apply_filters("sage/template/{$class}/data", $data, $template);
}, []);
echo \App\template($template, $data);

Is the same way Sage does in filters.php:59

1 Like