Bagisto Forum

    Bagisto

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Adding my custom javascript to the page

    Knowledge Base
    2
    4
    852
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      manatech last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • S
        shivam-webkul last edited by

        Hi, @manatech

        I got your question please have a look of that doc
        https://bagisto.com/en/how-tos-add-styles-or-scripts-in-bagistos-backend-or-storefront-layouts/ .

        Thanks

        1 Reply Last reply Reply Quote 0
        • M
          manatech last edited by

          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? **/
                  });
          
          1 Reply Last reply Reply Quote 0
          • S
            shivam-webkul last edited by

            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
            
            1 Reply Last reply Reply Quote 0
            • First post
              Last post