3

I'm trying to include a javascript file in my page layout file. I already have it inside the "PlaceHolderAdditionalPageHead" Content Placeholder, and it includes the file, however I need it to be included after the jQuery file that is included in my Master Page file. Otherwise I end up with javascript errors because '$' hasn't been declared yet.

Thank you for your assistance.

4
  • what does your master page code look like that is doing the jQuery include? May 21, 2014 at 22:17
  • I answered this a couple years back: sharepoint.stackexchange.com/questions/18068/…. #2 of my answer should work for you.
    – Rob D'Oria
    May 21, 2014 at 22:19
  • Thank you for your comment Rob. I'm coming from a PHP development background, so onzur's solution of repositioning existing code, rather than adding more code, makes more sense to me.
    – scullytr
    May 22, 2014 at 16:55
  • That's only a recommended approach if you require that script across all pages. The approach I suggested is recommended for page-specific scripts.
    – Rob D'Oria
    May 22, 2014 at 21:33

2 Answers 2

4

In the master page there is a place holder for the additionalpagehead . Make sure the jQuery reference Comes before that. that way the jQuery reference will be processed first

0

My comment was a little vague and my answer to that other question didn't entirely address your situation. You will want to reference Christian Glessner's write-up on SP SOD, with a focus on either registering your script to LoadAfterUI (should ensure jquery is loaded) or using the registerSodDep to register the dependency between your script and jquery if LoadAfterUI does not consistently produce the desired result.

I've used both for different solutions...either should work for you. Note the requirement on the location of the script if you go the on-demand route. As Christian suggests you should strongly name your script file if you're going to deploy it to the root of layouts.

http://www.ilovesharepoint.com/2010/08/sharepoint-scripts-on-demand-spsod.html

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.