including JS files conditionally

10 views
Skip to first unread message

Marc Esher

unread,
Oct 8, 2008, 7:54:06 AM10/8/08
to col...@googlegroups.com
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?

thanks.

marc

Ernst van der Linden

unread,
Oct 8, 2008, 7:57:41 AM10/8/08
to col...@googlegroups.com
1. Create a view with all plugin calls;
2. Call renderView() on everyview which needs it.

Hope that helps.

Ernst

Marc Esher

unread,
Oct 8, 2008, 8:06:01 AM10/8/08
to col...@googlegroups.com
i'll give 'er a shot. Thanks Ernst.

Ernst van der Linden

unread,
Oct 8, 2008, 8:09:43 AM10/8/08
to col...@googlegroups.com
Of course you can also create a plugin which renders the jquery stuff.

Jonathan Burnham

unread,
Oct 8, 2008, 8:20:48 AM10/8/08
to col...@googlegroups.com

Marc Esher

unread,
Oct 8, 2008, 8:42:40 AM10/8/08
to col...@googlegroups.com
yup, got it all going. working great. thanks guys!

Andrew Scott

unread,
Oct 8, 2008, 10:39:58 PM10/8/08
to col...@googlegroups.com
Mark,

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
solution.


--
Senior Coldfusion Developer
Aegeon Pty. Ltd.
www.aegeon.com.au
Phone: +613 9015 8628
Mobile: 0404 998 273

Ernst van der Linden

unread,
Oct 9, 2008, 8:38:18 AM10/9/08
to col...@googlegroups.com
Take a look at the Spry plugin and see how I solved this 'problem'.

Ernst

Reply all
Reply to author
Forward
0 new messages