1

in Sharepoint, is there anything similar to master/base page of master page?

I'm working on a task which needs to add a 3rd-party javascript to all pages in the farm. However, in the farm, there are many site collections, and there are many subsites/pages under each site collection. They are using different master pages.

One solution is to add the code to each master pages one by one, which will take a long time. That's why I'm having this question: is there anything similar to master/base page of master page? So I only need to add it to that?

or, this is never heard in SP, :)?

1

I have no idea what a master/base page of master page refers to, but I can tell you how to reference JS files globally.

There are a few different ways to do this actually, but my preferred method is a CustomAction. You deploy this as a Feature through a solution package. Then you need to activate your feature throughout your farm, either through a Feature stapler or a PowerShell script.

Here's a post that will explain the concept: http://www.spdeveloper.co.in/tipsntricks/pages/referencing-js-files-using-custom-action.aspx

Other methods, which others on this site will undoubtedly endorse, include delegate controls or simply adding them to a custom master page. I prefer my approach because it's simple, and has the least amount of maintenance overhead.

1

Look in to the AdditionalPageHeadDelegate control, as long as it is used in every masterpage (it should be), you can inject a script file or really any HTML markup by adding your own control in this delegate.

See this post for details http://blogs.msdn.com/b/kaevans/archive/2011/04/06/adding-jquery-to-every-page-in-sharepoint-with-delegate-controls.aspx

0

Easiest and best approach is to develop a delegate control which will be loaded into the AdditionalPageHead.

Why is the delegate control the best approach? Because it is the most flexible solution at any given time. Yes, a CustomAction can be used, but don't use a CustomAction to solve something a delegate control is designed to do.

  1. Create a UserControl (preferably placed in the CONTROLTEMPLATES folder) and add your javascript in it.
  2. Create an Empty Element and add the following xml to it: <Control Id="AdditionalPageHead" Sequence="90" ControlSrc="~/_CONTROLTEMPLATES/MySolution/MyControl.ascx" />
  3. Add a new feature, make it Site scoped and add the Empty Element to that feature.

Next step is to deploy your solution and activate the feature on all site collections. Use PowerShell to faster activate it across the farm.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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