# Use '@stack' & '@push' to push js file in blade.php

**URL:** <https://discourse.roots.io/t/use-stack-push-to-push-js-file-in-blade-php/22511>\
**Category:** sage\
**Tags:** blade, sage10\
**Created:** [March 9, 2022, 5:36pm UTC](https://discourse.roots.io/t/use-stack-push-to-push-js-file-in-blade-php/22511 "2022-03-09T17:36:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shinhon](https://discourse.roots.io/user_avatar/discourse.roots.io/shinhon/32/10346_2.png) [@shinhon](https://discourse.roots.io/u/shinhon)\
**Post date:** [March 9, 2022, 5:36pm UTC](https://discourse.roots.io/t/use-stack-push-to-push-js-file-in-blade-php/22511/1 "2022-03-09T17:36:47Z")

</div>

I am trying to push extra js file only in `page.blade.php` file.

for example  
layouts/app.blade.php

```auto
<a class="sr-only focus:not-sr-only" href="#main">
  {{ __('Skip to content') }}
</a>

@include('sections.header')

  <main id="main" class="main">
    @yield('content')
  </main>

  @hasSection('sidebar')
    <aside class="sidebar">
      @yield('sidebar')
    </aside>
  @endif

@include('sections.footer')

@stack('scripts')

```

page.blade.php

```auto
@extends('layouts.app')

@section('content')
  @while(have_posts()) @php(the_post())
    @include('partials.page-header')
    @includeFirst(['partials.content-page', 'partials.content'])
  @endwhile
  <div class="text-xl text-blue-400">heyeyeye</div>
@endsection

@push('scripts')
  <script src="{{ asset('page.js') }}"></script>
@endpush

```

But the script tag ended up added under footer tag(It should be add after app.js has be called).

 ![Screen Shot 2022-03-10 at 1.34.17 AM](https://discourse.roots.io/uploads/default/original/2X/7/74480755ad304258a723dac322fba25779524aa3.png)

Is there anyway for me to push script tag in different blade.php file?

Sorry for my poor English.

---

<div class="post-metadata">

**Author:** ![alwaysblank](https://discourse.roots.io/user_avatar/discourse.roots.io/alwaysblank/32/11206_2.png) [@alwaysblank](https://discourse.roots.io/u/alwaysblank)\
**Post date:** [March 10, 2022, 11:11am UTC](https://discourse.roots.io/t/use-stack-push-to-push-js-file-in-blade-php/22511/2 "2022-03-10T11:11:54Z")

</div>

The `app.js` line is printed by the `wp_footer()` call in `index.php`, which wraps the content that Blade generates: you won’t be able to use `@push` to put content there.

If you want to enqueue scripts only on a particular template, I’d recommend using `wp_enquque_script()` with a conditional, i.e.

```auto
if (is_page()) {
  wp_enqueue_script('page-js', 'page.js', ['app'], false, true);
}

```

---

<div class="post-metadata">

**Author:** ![MWDelaney](https://discourse.roots.io/user_avatar/discourse.roots.io/mwdelaney/32/5755_2.png) [@MWDelaney](https://discourse.roots.io/u/MWDelaney)\
**Post date:** [March 10, 2022, 7:50pm UTC](https://discourse.roots.io/t/use-stack-push-to-push-js-file-in-blade-php/22511/3 "2022-03-10T19:50:15Z")

</div>

For anyone looking for general info on Blade `@stack`s, check out this post from a few years ago:

> [@How blade @stacks make my life better](https://discourse.roots.io/t/how-blade-stacks-make-my-life-better/10121):
>
> If you haven’t used @stacks yet, you might be missing out on a neat tool. I have a site that needs an on-page anchor navigation (I’m using a scrollspy effect and position: sticky to make it useful) on product pages. The anchors are to lists of related content from elsewhere on the site; related whitepapers, related FAQs, etc. The difficulty was that each product needing this nav had a different set of related content. Some had FAQs but no whitepapers; some had whitepapers but no FAQs; some had …
