I have used this javascript function to like my publishing pages. The problem is that I can only like the page if I am at the current page since the javascript uses the _spPageContextInfo variable.

The thing I want to do is to like a page from i.e a news archive or a start page that lists a summary of the page, for example title, preamble, image and date.

How can I get the _spPageContextInfo from a list item, and then set that object in a .aspx page?

Here is an example how I think it would be:

Page layout:

<span class="LikeButtonImage" data-spPageContext="_spPageContextInfo"></span>


$(“.LikeButtonImage”).click(function () {
   var spPC = $(this).data("spPageContext");

And in the code set the data attribute for each list item.

Appreciate your help!

1 Answer 1


_spPageContextInfo is available on any SharePoint page. But you need not only this object, but also ListID (Pages library id) and ItemID (page id). You have to get them from your server and put into data attributes. Then inside these javascript functions replace _spPageContextInfo.pageListId and _spPageContextInfo.pageItemId with attribute values.

By the way, how do you suppose to render these buttons? Maybe you can try to use List View Web Part + Client Side Rendering? It's very easy to implement custom likes with it.

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.