Docs

View Render Event

edit on github

With the help of the view_render_event(), you can inject anything before or after the content of a template.

View Render Event

To render any template before or after any function we may use view_render_event. You can define any event (view_render_event()) in the template by following steps:

Steps to render View

  1. Create an event in the blade file in which you want to render any content before or after any content of that template:
    !! view_render_event('bagisto.shop.test.before') !!

As you can see, bagisto.shop.test is the event name here that is defined in a random blade file of the project.

  1. Now you have to listen to the event at EventServiceProvider file and in the boot method like:
    Event::listen('bagisto.shop.test.before', function($viewRenderEventManager) {
    $viewRenderEventManager->addTemplate('template file path that you want to inject);'
    }

As you can see, you have to add the path of the template here that you want to render.

After that, this will automatically fire and your template will be injected before the content.

  1. Make sure that you have registered EventServiceProvider in your ServiceProvider’s.