1
votes

I am using SharePoint 2013 on-prem. I am attempting to use the Title attribute (column) from Site Pages (list) as the pageTitle for the corresponding page. I know that I could hard-code going through the Site Pages list for the title, but I would like to use some property on the page or a direct call to get the page's title and replace the pageTitle tag.

2
document.title ?Lee Taylor
That actually provides the site and the name, not the title field of the page. So on my site page called Project on my Development site with a title of Project Summary I would get Development - ProjectSteve Harvancik

2 Answers

0
votes

I understand you want to display the Site Pages Title column in the corresponding page, then you can use Rest API to get it and display in the page:

<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
        $.ajax({
                   url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Site Pages')/items?$filter=Id eq '"+_spPageContextInfo.pageItemId+"' ",
                   method: "GET",
                   headers: { "Accept": "application/json; odata=verbose" },
                   success: function (data) {
                            $("#PageTitle").html(data.d.results[0].Title);

                  },
                  error: function (data) {
                      alert("Error: "+ data);
                 }
          });
</script>
<div id="PageTitle"></div>

enter image description here

This is the return Json format for the page item: enter image description here

0
votes

using the SharePoint context you could use SPContext.Current.Item["Title"] for documents or SPContext.Current.List.Title for lists.