5

I've added my JavaScript code by including the script links in the PlaceHolderAdditionalPageHead <asp:Content> tag. Including this has caused a yellow warning stating

The current page has been customized from its template. Revert to template.

I understand that I can simply remove the message through some JavaScript code, but how does Microsoft recommend I include JavaScript code and jQuery without disrupting the site template?

5 Answers 5

5

It really depends what page you are talking about (master page, .aspx page, etc.), but you can add your script references in a Content Editor Web Part (CEWP) if you don't want to customize your pages.

6

Are you running SharePoint 2010? If so, you can include your scripts using a feature: it is now possible to have a CustomAction with ScriptLink as a location. This will leave the masterpage unmodified while at the same time making jQuery (and any other scripts you need) available across the entire site collection. More information is in Deploying and Using jQuery with a SharePoint 2010 Sandboxed Solution.

1
  • Completely forgot about that one! That is, indeed, a nice solution.
    – Bas Lijten
    Commented Aug 29, 2011 at 7:15
3

A warning doesn't mean that you did something wrong.

As far as I know there is no recommendation from Microsoft. There are many ways to add a script to a page, and your choice will depend on your specific use case and personal preferences.

Do you need jQuery on many pages? Then you may want to include it in a custom Master page. Do you need it on just one page? Then the easiest way is to call it from a Content Editor Web Part.

1
  • I like this contribution though not as complete as some of the other answers just because it mentions that the warning is just a warning.
    – Tom Resing
    Commented Aug 30, 2011 at 20:00
3

As Marc D Anderson stated, you can add script references in various ways. If you want to add JavaScript code on a single page, you can indeed use a Content Editor webpart, but I really like the solution of creating a feature and use delegate controls to add the JavaScript code to your page layouts. That way, you don't have to customize any page layouts.

Read jQuery Templates and the Sharepoint 2010 Object Model for information on adding JavaScript code to pages.

1
  • 2
    delegate controls means filesystem deployment, if you are on SP2010 and in a sandboxed environment this won't work
    – Colin
    Commented Aug 26, 2011 at 20:27
2

It is not recommended to customize any out of the box master pages or page layouts in SharePoint. Instead, copy your existing master page to a new name and make your customizations in that, then set the new master page as the master page for your site collection.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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