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>

`

3
  • 2
    You can give answers to your own questions in SE, Adam! If you do this, your question no longer appears as unanswered :D
    – carlcs
    Jul 28, 2014 at 20:39
  • 1
    I think this is a better Q&A than the other one, but it's still a duplicate.
    – Matt Stein
    Jul 29, 2014 at 15:45
  • Good call @MattStein that would have been exactly what I needed. Jul 29, 2014 at 16:21

1 Answer 1

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'));

Not the answer you're looking for? Browse other questions tagged or ask your own question.