• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Register
  • Login
Bagisto Forum

Bagisto

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

Adding my custom javascript to the page

Knowledge Base
2
4
1.3k
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 8 Apr 2020, 20:55

    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 9 Apr 2020, 06:37

      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 9 Apr 2020, 08:16

        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 9 Apr 2020, 10:15

          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
          3 out of 4
          • First post
            3/4
            Last post