Adding my custom javascript to the page



  • Hi
    In case of attachingcustom stylesheet to the active theme we know that we should use something like this:

    Event::listen('bagisto.admin.layout.head', function($viewRenderEventManager) {
                $viewRenderEventManager->addTemplate('helloworld::layouts.style');
            });
    

    But how about a custom js? Suppose that I have a javascript file. I know that there is a event in the system named bagisto.shop.layout.body.after that we can write a listener for it and attach our javascript to the page. but how we can do this?





  • Thank you but that article is about registering css files but I want to attach a javascript. For example I want to attach the resides in /packages/CompanyName/ProjectName/src/Resources/assets/js/app.js to the page. Now what code I should write in the placeholder?

    Event::listen('bagisto.shop.layout.body.after', function($viewRenderEventManager) {
                /** PlaceHolder: What code I should write here? **/
            });
    


  • Hi, @manatech

    for the js you just need to add you js into master.blade.php

    @extends('admin::layouts.master')
    
    @push('scripts')
        <script type="text/javascript" src="{{ bagisto_asset('your js path') }}"></script>
    @endpush.
    
    Thanks
    

Log in to reply