# Add via plugin a script block in every page/view

**URL:** <https://discourse.cakephp.org/t/add-via-plugin-a-script-block-in-every-page-view/11515>\
**Category:** Need Help\
**Tags:** help\
**Created:** [September 14, 2023, 11:40am UTC](https://discourse.cakephp.org/t/add-via-plugin-a-script-block-in-every-page-view/11515 "2023-09-14T11:40:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ProDaniBest](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/prodanibest/32/2521_2.png) [@ProDaniBest](https://discourse.cakephp.org/u/ProDaniBest)\
**Post date:** [September 14, 2023, 11:40am UTC](https://discourse.cakephp.org/t/add-via-plugin-a-script-block-in-every-page-view/11515/1 "2023-09-14T11:40:45Z")

</div>

Hello 🙂

Maybe you know a simple and quick way to permanently add a Javascript file to all views in the script block using the plugin system. How can this be achieved?

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [September 14, 2023, 3:33pm UTC](https://discourse.cakephp.org/t/add-via-plugin-a-script-block-in-every-page-view/11515/2 "2023-09-14T15:33:36Z")

</div>

There is already this present in the app template

> <https://github.com/cakephp/app/blob/5.x/templates/layout/default.php#L34>

So you can then do something like

```auto
<?php $this->append('script'); ?>
<script>
    alert('Hello!');
</script>
<?php $this->end(); ?>

```

to your sub-template file

See [Views - 4.x](https://book.cakephp.org/4/en/views.html#using-view-blocks)

---

<div class="post-metadata">

**Author:** ![ProDaniBest](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/prodanibest/32/2521_2.png) [@ProDaniBest](https://discourse.cakephp.org/u/ProDaniBest)\
**Post date:** [November 15, 2023, 5:15pm UTC](https://discourse.cakephp.org/t/add-via-plugin-a-script-block-in-every-page-view/11515/3 "2023-11-15T17:15:16Z")

</div>

Thanks Kevin 👍 your solution works.
