Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

This question already has an answer here:

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>

`

share|improve this question

marked as duplicate by Josh Angell, Matt Stein Jul 29 at 15:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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 at 20:39
    
Thanks @ChristianSeelbach, I just edited and did that. –  Adam McCombs Jul 28 at 20:43
1  
I think this is a better Q&A than the other one, but it's still a duplicate. –  Matt Stein Jul 29 at 15:45
    
Good call @MattStein that would have been exactly what I needed. –  Adam McCombs Jul 29 at 16:21

1 Answer 1

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'));
share|improve this answer

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