1

Using embedded script on a page from "Site Pages", I want to display the Modified date at the bottom of the page (I also want to display a custom column called "Page Owner", but I have figured out how to get that generically).

I can get the info about ALL of the pages in Site Pages, my challenge is to return info just for the page that is currently displayed.

How do I sense the current page and display just its info?

Here is the code that works for all pages:

   function getData() {
    $().SPServices({
        operation: "GetListItems",
        async: true,
        listName: "Site Pages",
        CAMLViewFields: "<ViewFields>" +
                "<FieldRef Name='LinkFilename'/>" +
                "<FieldRef Name='Page_x0020_Owner'/>" +
                "<FieldRef Name='Modified'/>" +
            "</ViewFields>",
        completefunc: function(xData, Status) {
            $(xData.responseXML).SPFilterNode("z:row").each(function() {
                var liHtml = "<li>" + $(this).attr("ows_LinkFilename") +
                    ' // ' + $(this).attr("ows_Modified") + 
                    ' // ' + $(this).attr("ows_Page_x0020_Owner") + "</li>";
                $("#tasksUL").append(liHtml);
            });
        }
    });
}

1 Answer 1

1

Using the following scripts in each page. It will display the current page info.

<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.7.1a/jquery.SPServices-0.7.1a.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
    // get the id of the current page
    var pageId = _spPageContextInfo.pageItemId;
    getData(pageId);
});

  function getData(pageId) {
    $().SPServices({
        operation: "GetListItems",
        async: true,
        listName: "Site Pages",
        CAMLViewFields: "<ViewFields>" +
                "<FieldRef Name='LinkFilename'/>" +
                "<FieldRef Name='Author'/>" +
                "<FieldRef Name='Modified'/>" +
            "</ViewFields>",
        CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Integer'>" + pageId + "</Value></Eq></Where></Query>",
        completefunc: function(xData, Status) {
            $(xData.responseXML).SPFilterNode("z:row").each(function() {
                var liHtml = "<li>" + $(this).attr("ows_LinkFilename") +
                    ' // ' + $(this).attr("ows_Modified") + 
                    ' // ' + $(this).attr("ows_Author") + "</li>";
                $("#tasksUL").append(liHtml);
            });
        }
    });
}
</script>
0

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.