<p>Nope, but you can use the <a href="https://craftcms.com/docs/templating/includejsfile" rel="nofollow"><code>{% includeJsFile %}</code></a> tag to include the file(s) from your widget template. In whatever template you render in your widget's <code>getBodyHtml()</code> method, add this:</p>

<pre><code>{% includeJsFile "https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY" %}
</code></pre>

<p>If you need to queue up several files, you'll need several <code>{% includeJsFile %}</code> tags. There's also a <code>{% includeCssFile %}</code>, if you need to add some external CSS, as well.</p>

CC BY-SA 3.0
2016-10-19T12:59:45.083Z
2016-10-19T12:59:45.083Z
Mats Mikkel Rummelhoff
<p>You know that init() would fire everytime an action is done, so you would load multiple google map apis it is mostly used for hooking into Events.</p>

<p>I would try something else to load it in.</p>

<p>Control Panel JS plugin for craft and then by there load in your javascript. &lt;- works good if i remember correctly</p>

CC BY-SA 3.0
2016-10-19T12:55:24.720Z
2016-10-19T12:55:24.720Z
Bram B
<p>Is there an easy way to check if the current page is the Dashboard?
I have a widget that needs several Javascript resources but if I include them in the widget library I get a google maps error that I should not do that.
<code>You have included the Google Maps API multiple times on this page. This may cause unexpected errors.</code></p>

<p>I could make a workaround and set a static public variable to false after the first include but that would be kinda dirty.</p>

<p>So all I want to know id there is something like</p>

<pre><code>function init()
{
    if (craft()-&gt;isDashBoard()) {
        //include all JS ressources
    }
}
</code></pre>

<p>or if there is a better way to include Javascript. </p>

<plugin-development>
Plugin init check if current page is dashboard
# Plugin init check if current page is dashboard

(Asked by: username_0 on 2016-10-19)

Is there an easy way to check if the current page is the Dashboard?
I have a widget that needs several Javascript resources but if I include them in the widget library I get a google maps error that I should not do that.
You have included the Google Maps API multiple times on this page. This may cause unexpected errors.
I could make a workaround and set a static public variable to false after the first include but that would be kinda dirty.
So all I want to know id there is something like
function init()
{
    if (craft()->isDashBoard()) {
        //include all JS ressources
    }
}

or if there is a better way to include Javascript.

**Tags:** plugin-development


---

## 2 answers

### Answer by username_1 on 2016-10-19. Score: 3 | Accepted answer

Nope, but you can use the {% includeJsFile %} tag to include the file(s) from your widget template. In whatever template you render in your widget's getBodyHtml() method, add this:
{% includeJsFile "https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY" %}

If you need to queue up several files, you'll need several {% includeJsFile %} tags. There's also a {% includeCssFile %}, if you need to add some external CSS, as well.


---

### Answer by username_2 on 2016-10-19. Score: 1

You know that init() would fire everytime an action is done, so you would load multiple google map apis it is mostly used for hooking into Events.

I would try something else to load it in.

Control Panel JS plugin for craft and then by there load in your javascript. <- works good if i remember correctly


---

