0

i recently tried to modify a view with JSLink, modification works very good, but userfields are not correct provided if JSLink is in use.
By default a userfield is rendered blank at first glance. Looking into HTML it renders as

<span class="ms-floatLeft ms-peopleux-vanillaUser">
   <span class="ms-floatLeft ms-peopleux-vanillaUser">
      <span class="ms-floatLeft ms-peopleux-vanillaUser">
         <span class="ms-floatLeft ms-peopleux-vanillaUser">
            <span class="ms-floatLeft ms-peopleux-vanillaUser">
</span></span></span></span></span>

Debugging context.CurrentItem provides that the given value is only the UserID
CurrentItem:

{
   Title: "Test", 
   Editor: "1", 
   PublishingPageContext:"...", 
   ...
}

JSLink:

(function () { 
    var bodyFiledContext = {}; 
    bodyFiledContext.Templates = {}; 
    bodyFiledContext.Templates.Fields = { 
        "PublishingPageContent": { "View": bodyFiledTemplate }
    };  
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(bodyFiledContext); 
})(); 

Any chance to get the username?

1

Make sure user field is included into List View.

Then, you could access user field properties as shown on picture below

enter image description here

(function () { 

    function renderPageContent(rCtx){

        var item = rCtx.CurrentItem;
        if(item.Author.length > 0) {
           var authorId = item.Author[0].id; 
           var authorName = item.Author[0].title;            
        }
    }


    var viewContext = {}; 
    viewContext.Templates = {}; 
    viewContext.Templates.Fields = { 
        "PublishingPageContent": { "View": renderPageContent }
    };  
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(viewContext); 
})(); 
  • 1
    As you mention, it should be like this, but it was not. I only had the UserID String instead of a User Object although having userfield in view. This is very strange. I tried to write an other JSLink for an other List and it worked instantly. Back to this list i deleted the ListWebPart and added it anew, guess what? it worked... Atm i was not able to reproduce the first behavior. Never the less thank you for your help! – Rafael Dabrowski Jun 26 '14 at 12:55

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.