Is is possible to inject a View Model on every route? #5454
-
Hi, I have injected a View Model https://statamic.dev/view-models in the Pages Collection which is working as I want it to, but is there a way I can inject the same View Model on ... essentially everything, so that it's available no matter what type of collection/entry/route I am on? content/collection/pages.yaml
At the moment, the additional variables I'm setting in the View Model (which I'm using in the website footer) are not accessible from, for example, the 404 page. If not, I can inject it on all collections, which is not a problem, but is there a way I can inject these variables on the 404 page too? I can't just use a global variable as the value needs to be dynamic based on the logic in the View Model. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
In your AppServiceProvider's boot method, you can add a view composer: View::composer('*', function ($view) {
$view->with('foo', 'bar');
});
|
Beta Was this translation helpful? Give feedback.
In your AppServiceProvider's boot method, you can add a view composer: