Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add callback before View renders #706

Closed
aerni opened this issue Dec 2, 2021 · 2 comments
Closed

Add callback before View renders #706

aerni opened this issue Dec 2, 2021 · 2 comments

Comments

@aerni
Copy link

aerni commented Dec 2, 2021

Is it possible to add something like abeforeRender callback to Statamic\View\View? Similar to the Cascade::hydrated() callback added here: statamic/cms#4359

I use the Cascade::hydrated() callback to add additional data to the context. This does mostly what I need it to do. But there are cases where a View adds additional data to the cascade in the gatherData() method, e.g. in the NotFoundHttpException.

So the final context data can be different to what's available in the Cascade::hydrated() callback. I need a way to have the last say before the context gets added to the page.

@aerni
Copy link
Author

aerni commented Dec 2, 2021

I found that Laravel already provides a way to do so:

\Illuminate\Support\Facades\View::composer('*', function ($view) {
  $view->with('foo', 'bar');
});

The view in this callback has all the data from the context and additional data from Statamic's views available.

@aerni aerni closed this as completed Dec 2, 2021
@jackmcdade
Copy link
Member

Bingo! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants