4

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.

<script src="{{ resourceUrl('plugin/js/public.js') }}"></script>

`

Adam McCombs
  • 1,695
  • 12
  • 25

1 Answers1

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'));
Adam McCombs
  • 1,695
  • 12
  • 25