Bare minimum page to get _spPageContextInfo loaded
-
29-09-2020 - |
Question
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:
But it's a web part page.
I've also seen this other post:
suggesting you just need script manager in a form, but it doesn't seem to work
Solution
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