0

I need to display on a few article pages so I do not need the code to be placed in the page layout or in the master page. Is this possible?

The model is what appears on the Enterprise wiki page on top.

enter image description here

1

Use FieldValue in your publishing page layout.

Demo:

<div id="page_information">
            Page last modified:<SharePoint:FieldValue FieldName="Modified" runat="server" id="modified" ControlMode="display" /></div>

enter image description here enter image description here

  • I did not write I need it on every page, I just need it as a script on some pages – susan Aug 21 '18 at 7:34
  • 1
    Create a custom page layout, the page which need display the time, use the page layout. Otherwise, I think you need JavaScript code to display this information dynamically. – Lee_MSFT Aug 21 '18 at 8:05
0

You can use the below mentioned code in a script editor webpart.

Create some html as:

<span id="modifiedDate"></span>

After that, add jQuery reference and then run the below code:

function getModifiedDate(){
    var itemId = _spPageContextInfo.pageItemId;

    $.ajax({
            url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Pages')/items?$select=Modified&$filter=ID eq " + itemId,
            method: "GET",
            headers: { "Accept": "application/json;" },
            success: function (data) {        
                console.log(data.value.Modified);
                $("modifiedDate").html("Page Modified on: " + data.value.Modified);
            },
            error: function (data) {
                console.log(data);
            }
    });
}

$(document).ready(function() {
     getModifiedDate();    
});
  • where do I place the big code above? does it matter that the column name is "Modified" and the internal name for Modified is LastModifiedTime? – susan Aug 22 '18 at 13:54
  • Place it in a Script editor webpart, add jquery reference first and then add this code in <script> tags. The column name is Modified – Gautam Sheth Aug 22 '18 at 13:56
  • I added this as a jquery reference <script src="jquery-1.12.4.min.js"></script> with your code in between and it didn't display anything, and what is the relation of the line you posted above the code? (the span one) – susan Aug 22 '18 at 14:07
  • the rest call will fetch the modified data and add it to the span tag. You might need to work on the styling part – Gautam Sheth Aug 22 '18 at 14:09
  • so I put the rest call and span line in the same script editor? what jquery reference I need to add? – susan Aug 22 '18 at 14:22

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.