As explained by Jan Tielens (http://weblogs.asp.net/jan/archive/2008/11/20/sharepoint-2007-and-jquery-1.aspx there are usually three solutions considered to be available to do that:
- Add a <script src> tag in a Content Editor Web Part
- Add a <script src> tag in the Master Page itself
- Add a <script src> tag dynamically in the <head> using a DelegateControl placed in the standard master pages
In my case, only the third solution was usable. So I went with it, created my feature, added it to my solution.
The story would have ended here if it wasn’t for a detail I discovered quickly enough; the standard publishing pages (BlueGlassBand and so forth) do not have the AdditionalPageHead delegate control defined. Thus my solution worked really well with collaboration pages but failed on publishing pages.
The obvious solution was to modify the master page used by my client to add the Delegate Control tag but the client didn’t want any modification to the master page. Thus I was at this point :
After digging a bit I found a very surprising (to me at least) but fully working solution. Use a Custom Action.
Before you start thinking I am nuts, let me explain, If you take a close look at the MSDN you will see that you can specify a ControlAssembly and a ControlClass, guess what, the class specified will do the actual rendering. Custom Actions aren’t just for Site Action Menu entries, ECB and so forth.
So here is more detail:
- Create a class inheriting from CompositeControl
- Override the constructor so that I can plug a method in the Load event.
- In my method triggered on load, access the page header and add a LiteralControl to declare the scripts and css I need
And here is a stripped down but fully working version of my code :
<?xml version="1.0" encoding="utf-8" ?>
Here you go, a non-intrusive quite generic solution to plug additional resources into SharePoint.