I'm trying to define a display template for one of my site columns by using XSLT. One of the things I would need is the loginname (DOMAIN\user) of the currently logged in user.

There's one way described here, using parameterbindings. But I'm trying to make this as generic as possible, so setting the parameterbindings for each web part is unrealistic.

I found a way to get the user's ID on this page. And, based on the ddwrt namespace I discovered the method UserLookup

So I tried the following snippet:

<xsl:value-of select="ddwrt:UserLookup,($Userid,'ID')" />

But unfortunately this just returns a blank string. Where am I going wrong? If my current approach won't work, what other way is there?

  • 1
    You can try to use <xsl:value-of select="$UserID" /> to display the current username. Commented Sep 4, 2014 at 7:31
  • I tried that but got an XslLoadException that the parameter 'UserID' doesn't exist. 'Userid' does exist, but that's the ID of the user (the number), not the loginname. Commented Sep 4, 2014 at 7:36
  • This might help you: blogs.msdn.com/b/joshuag/archive/2008/06/03/… Commented Sep 4, 2014 at 7:45
  • You might have to add the parameter binding; see my answer below.
    – bgmCoder
    Commented Dec 10, 2015 at 16:59
  • I've tried this - it can work in a DispForm.aspx without issue, but it doesn't work in fldtypes.xsl - I think because the regular list-views do not include the parameter binding.
    – bgmCoder
    Commented Dec 10, 2015 at 17:02

3 Answers 3


You have to do a couple things.

First, you might need to make sure your xsl connector has this parameter binding:

<ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>

And make sure this is in there:


Then, add this parameter to give your xsl access to that value:

<xsl:param name="UserID"/>

Now, in your xsl, you can do this:

UserID: <xsl:value-of select="$UserID"/><br />
<xsl:value-of select="ddwrt:UserLookup(string($UserID) ,'ID')" /><br />
<xsl:value-of select="ddwrt:UserLookup(string($UserID) ,'EMail')" />

I figured this out from this page and from here, especially. I tried this in a custom DispForm.aspx page (because it was an easy place to test) and it works like a charm.


Try this.

<xsl:value-of select="ddwrt:UserLookup(string($Userid) ,'ID')" />

You had "," after UserLookup.


I use a different way to do the same thing. I use the _spPageContextInfo (an object that is possible to return in every sp page).

Example for returning name of Current User:

<script type="text/javascript"​>  
var userid= _spPageContextInfo.userId;  
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")";             
var requestHeaders = { "accept" : ​"application/json;odata=verbose" };   
        url : requestUri,
        contentType :"application/json;odata=verbose",
        headers : requestHeaders,
        success : onSuccess,
        error : onError   }); 
function onSuccess(data, request)
{  ​
var loginName = data.d.Title;
function onError(error) 
} ​​

More about _spPageContextInfo:

Click Here

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.