<p>You can use these and Craft automatically adds the files in the appropriate spots.</p>

<pre><code>$output = craft()-&gt;templates-&gt;includeJsFile(UrlHelper::getResourceUrl('plugin/script.js'));

$output .= craft()-&gt;templates-&gt;includeCssResource(UrlHelper::getResourceUrl('plugin/styles.css'));
</code></pre>

CC BY-SA 3.0
2014-07-28T20:42:53.547Z
2014-07-28T20:42:53.547Z
Adam McCombs
<p>I've got a variable (widget is a better word) that I want to output with accompanying CSS and/or JS. </p>

<p>I'm rendering the variable (widget) with the following</p>

<pre><code>return TemplateHelper::getRaw($output);
</code></pre>

<p>I realize the following exists but other than inline js/css is there a way to output the widget and include CSS/JS by only using a single variable? I want to make this as simple as possible.</p>

<pre><code>&lt;script src="{{ resourceUrl('plugin/js/public.js') }}"&gt;&lt;/script&gt;
</code></pre>

<p>`</p>

CC BY-SA 3.0
2014-07-28T20:39:16.147Z
You can give answers to your own questions in SE, Adam! If you do this, your question no longer appears as unanswered :D
carlcs
CC BY-SA 3.0
2014-07-29T15:45:22.657Z
I think this is a better Q&A than the other one, but it's still a duplicate.
Matt Stein
CC BY-SA 3.0
2014-07-29T16:21:54.267Z
Good call @MattStein that would have been exactly what I needed.
Adam McCombs
<plugin-development><plugins>
How to include JS and CSS resources for a plugin variable
# How to include JS and CSS resources for a plugin variable

(Asked by: username_0 on 2014-07-28)

I've got a variable (widget is a better word) that I want to output with accompanying CSS and/or JS. 
I'm rendering the variable (widget) with the following
return TemplateHelper::getRaw($output);

I realize the following exists but other than inline js/css is there a way to output the widget and include CSS/JS by only using a single variable? I want to make this as simple as possible.


`

**Tags:** plugin-development, plugins

> **Comments:**
> **username_1**: You can give answers to your own questions in SE, Adam! If you do this, your question no longer appears as unanswered :D  
> **username_2**: I think this is a better Q&A than the other one, but it's still a duplicate.  
> **username_0**: Good call @MattStein that would have been exactly what I needed.  

---

## 1 answers

### Answer by username_0 on 2014-07-28. Score: 5

You can use these and Craft automatically adds the files in the appropriate spots.
$output = craft()->templates->includeJsFile(UrlHelper::getResourceUrl('plugin/script.js'));

$output .= craft()->templates->includeCssResource(UrlHelper::getResourceUrl('plugin/styles.css'));


---

