# How to import the Javascript code from php file in plugin

**URL:** <https://forum.getkirby.com/t/how-to-import-the-javascript-code-from-php-file-in-plugin/31510>\
**Category:** Questions\
**Tags:** v4\
**Created:** [May 1, 2024, 10:36pm UTC](https://forum.getkirby.com/t/how-to-import-the-javascript-code-from-php-file-in-plugin/31510 "2024-05-01T22:36:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Feng](https://avatars.discourse-cdn.com/v4/letter/f/82dd89/32.png) [@Feng](https://forum.getkirby.com/u/Feng)\
**Post date:** [May 1, 2024, 10:36pm UTC](https://forum.getkirby.com/t/how-to-import-the-javascript-code-from-php-file-in-plugin/31510/1 "2024-05-01T22:36:29Z")

</div>

```auto
<?php

use Kirby\Cms\App as Kirby;

Kirby::plugin('cookiebanner/kirby-cookie-plugin', [
    'blueprints' => [
        'cookiebannertab' => __DIR__. '/blueprints/tabs/cookiebannertab.yml'
	],
    'snippets' => [
        'cookiebanner' => __DIR__. '/snippets/cookiebanner.php'
    ],
    'translations' => [
        'de' => require __DIR__. '/translations/de.php',
        'en' => require __DIR__. '/translations/en.php',
    ],
]);

```

It seems that ‘blueprints’ and ‘translations’ work, but the file ‘cookiebanner’ =\> **DIR**. ‘/snippets/cookiebanner.php’ does not work. There is JS code in **DIR**. ‘/snippets/cookiebanner.php’, like:

```auto
<script>
    console.log("run here");
    <?php if($site->... == true): ?>
</script>

```

But the console log information will not show, how to import or use the javascript code in php file correctly in plugin?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [May 1, 2024, 10:51pm UTC](https://forum.getkirby.com/t/how-to-import-the-javascript-code-from-php-file-in-plugin/31510/2 "2024-05-01T22:51:57Z")

</div>

Unless your path is not correct, the script should run if you include the snippet somewhere. If you put anything else into that snippet, like just some text, does this work?

---

<div class="post-metadata">

**Author:** ![Feng](https://avatars.discourse-cdn.com/v4/letter/f/82dd89/32.png) [@Feng](https://forum.getkirby.com/u/Feng)\
**Post date:** [May 2, 2024, 10:11am UTC](https://forum.getkirby.com/t/how-to-import-the-javascript-code-from-php-file-in-plugin/31510/3 "2024-05-02T10:11:48Z")

</div>

Thanks for the reply. I added some text in the cookiebanner.php file, but it does not show.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [May 2, 2024, 11:02am UTC](https://forum.getkirby.com/t/how-to-import-the-javascript-code-from-php-file-in-plugin/31510/4 "2024-05-02T11:02:15Z")

</div>

Have you check your file path, spelling issues etc. Where do you include the snippet, please show your code.

---

<div class="post-metadata">

**Author:** ![Feng](https://avatars.discourse-cdn.com/v4/letter/f/82dd89/32.png) [@Feng](https://forum.getkirby.com/u/Feng)\
**Post date:** [May 2, 2024, 1:13pm UTC](https://forum.getkirby.com/t/how-to-import-the-javascript-code-from-php-file-in-plugin/31510/5 "2024-05-02T13:13:47Z")

</div>

The code structure is like this:

```auto
Plugin
  assets/
  blueprints/
    tabs/
      cookiebannertab.yml
  snippets/
    cookiebanner.php
  translations/
    de.php
    en.php
index.php
    

```

index.php

```auto
<?php

use Kirby\Cms\App as Kirby;

Kirby::plugin('cookiebanner/kirby-cookie-plugin', [
    'blueprints' => [
        'cookiebannertab' => __DIR__. '/blueprints/tabs/cookiebannertab.yml'
	],
    'snippets' => [
        'cookiebanner' => __DIR__. '/snippets/cookiebanner.php'
    ],
    'translations' => [
        'de' => require __DIR__. '/translations/de.php',
        'en' => require __DIR__. '/translations/en.php',
    ],
]);

```

cookiebanner.php

```auto
<script>
    console.log("run here");
    <?php if($site->... == true): ?>
</script>

```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [May 2, 2024, 1:15pm UTC](https://forum.getkirby.com/t/how-to-import-the-javascript-code-from-php-file-in-plugin/31510/6 "2024-05-02T13:15:07Z")

</div>

Thanks, but I also wanted to know where you include the snippet

---

<div class="post-metadata">

**Author:** ![Feng](https://avatars.discourse-cdn.com/v4/letter/f/82dd89/32.png) [@Feng](https://forum.getkirby.com/u/Feng)\
**Post date:** [May 2, 2024, 1:58pm UTC](https://forum.getkirby.com/t/how-to-import-the-javascript-code-from-php-file-in-plugin/31510/7 "2024-05-02T13:58:03Z")

</div>

Ah, i think this is the problem, i forgot to insert the snippet in template, thanks very much!
