16

I would like to know what is the minimum markup a SharePoint hosted aspx content page must have to get _spPageContextInfo loaded.

I plan to develop an angularjs SPA hosted on SharePoint site. I would like to avoid, if possible, master pages, web part pages and application pages. I plan to use client side object model and OData.

I've seen this post:

Can't use _spPageContextInfo

But it's a web part page.

I've also seen this other post:

http://sharepoint.aspcode.net/view/635399286724222582117090/napa-app-sppagecontextinfo-is-not-defined

suggesting you just need script manager in a form, but it doesn't seem to work

  • Thank you, after a day of searching your answer was the one that worked. – Carol Feb 15 at 21:42
  • @Carol, I'm glad my answer helped you. Incidentally, you posted your comment on the question, better post your comment on the answer, because it refers to the answer and not to the question. – Jesús López Feb 17 at 7:14
19

Ironically, after finishing the SPA aplication using a web part page, I found the bare minimum page to get _spPageContextInfo loaded:

<!DOCTYPE html>
<%@ Page language="C#" %>
<%@ Register Tagprefix="SharePoint" 
     Namespace="Microsoft.SharePoint.WebControls" 
     Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<html>
<head> 
</head>
<body>
    <form runat="server">
        <SharePoint:FormDigest ID="FormDigest1" runat="server"></SharePoint:FormDigest>
    </form>
</body>
</html>

If you want to use JSOM you will also need to load some javascript files:

<!DOCTYPE html>
<%@ Page language="C#" %>
<%@ Register Tagprefix="SharePoint" 
     Namespace="Microsoft.SharePoint.WebControls" 
     Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<html>
<head>
<meta name="WebPartPageExpansion" content="full" />
    <script src="/_layouts/1033/init.js"></script>
    <script src="/_layouts/MicrosoftAjax.js"></script>
    <script src="/_layouts/sp.core.js"></script>
    <script src="/_layouts/sp.runtime.js"></script>
    <script src="/_layouts/sp.js"></script>
 </head>
<body>
    <form runat="server">
        <SharePoint:FormDigest ID="FormDigest1" runat="server"></SharePoint:FormDigest>
    </form>
</body>
</html>

Replace version 14 with 15 to get it to work with SP 2013

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.