Вопрос

I've built out a solution with multiple masterpages/page layouts as features for a set of SharePoint 2010 publishing site collections.

One consistent request is to be able to grab the page owner contact email and display it in the footer of the masterpage. If the page Contact Email isn't entered, then I need to grab the page owner data from the People Picker, and grab the contact email from that.

I don't want to have to add every single publishing page layout to my solution, and manually add the Contact Email column into a place holder, that seems crazy to me. I figure there has to be a way to grab the page owner data from within the masterpage, but I can't figure it out. I started looking at the jQuery SPServices library, but so far I haven't been able to figure it out there, either.

Does anyone have any experience in adding a contact email using the supplied page owner contact information in the Masterpage?

Это было полезно?

Решение

OK, in order to resolve this, you need jQuery 1.7.x+ and the SPServices jQuery library version 0.7.2 or greater installed on your site.

Use GetListItems as the operation from SPServices.

I'm searching for pages within the Pages directory, so listName is "Pages".

The CAML View Fields are basically the columns for PublishingContactEmail and PublishingContact. I found those using u2u's CAML builder version 4.0.0.0

The ows_ variables can be found in the xml view of the POST object in firebug.

The ows_PublishingContact returns a long nasty string of the contact's information. Fortunately the email address is surrounded by ,#, which made splitting it into an array and then searching for an email @ easy, but that's why that's there.

function get_page_contact_email() {    
    var thisPageID = _spPageContextInfo.pageItemId;    
    var e;    
    $().SPServices({    
        operation: "GetListItems",    
        async: false,    
        listName: "Pages",    
        CAMLViewFields: "<ViewFields><FieldRef Name='PublishingContactEmail' /><FieldRef Name='PublishingContact' /></ViewFields>",    
        CAMLQueryOptions: "<QueryOptions><ExpandUserField>True</ExpandUserField></QueryOptions>",    
        completefunc: function (xData, Status) {    
            $(xData.responseXML).SPFilterNode("z:row").each(function () {    
                if (thisPageID == $(this).attr("ows_ID")) {    
                    if ($(this).attr("ows_PublishingContactEmail")) { // if page email is set    
                        e = $(this).attr("ows_PublishingContactEmail");    
                    } else if ($(this).attr("ows_PublishingContact")) { //otherwise use contact info    
                        var contact = $(this).attr("ows_PublishingContact").split(",#");    
                        for (var c = 0; c < contact.length; c++) {    
                            if (contact[c].indexOf("@") != -1) {    
                                e = contact[c];    
                            }    
                        }    
                    } else { //or nothing is set.    
                        e = false;    
                    }    
                }    
            });    
        }    
    });    
    return e;    
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top