including JS files conditionally

Hey All,
  This isn't a coldbox-specific question per se, though I'm wondering
if there are framework-friendly / best-practice ways of doing this in
coldbox. Basically, I have a bunch of jquery plugins whose JS I want
to include on certain pages, but not all. So I don't want to add them
into my main Layout file since most of the time they won't be needed.
And I don't want to add them in the individual view files because
that'll create a lot of redundancy; i.e. maybe 5-10 different views
will include this "suite" of plugins, and I don't want to duplicate
all those script calls in each view. I want to have a single call that
says "load the monster suite of plugins on this page".

  Back In the day I'd have just made a cfinclude with the appropriate
js includes and been done with it.

Any preferred method of achieving this in coldbox?



1. Create a view with all plugin calls;
2. Call renderView() on everyview which needs it.

Hope that helps.


i'll give 'er a shot. Thanks Ernst.

Of course you can also create a plugin which renders the jquery stuff.

This should help…

yup, got it all going. working great. thanks guys!


Sometimes we read the question differently, so I will add that there is
another way. A little more involved but will work, and it is untested.

The renderview (Luis correct me if I am wrong) should be able to be over
written to include a custom render, then you could have a plugin to setp JS
includes. That could be rendered then, the beauty about it is that depending
on how you approach it. You could have checks to see if it has been included
or not, so it doesn't get duplicated.

That is of course one method, but it could work. Or you could even include,
a more feature validation to include plugin compatability. So if it doesn't
exist, throws an error or whatever is needed to handle this in a template

Take a look at the Spry plugin and see how I solved this 'problem'.