0

I am currently having fun formatting a Content by Search web part in SharePoint 2013, but the formatting of individual values (through Property Mappings) has got me properly stuck.

I already have myself a custom Control_Custom.js and Item_Custom.js using the HTML display templates but there doesn't seem to be anything in there that governs how these property mappings are formatted / rendered.

Lets take a look at the formatting of a Date/Time field which always outputs in the format "dddd, MMMM d, yyyy".

For example - Tuesday, February 5, 2013

I have tried pulling through various different Property Mappings into my Content by Search including both:

  • Created
  • CreatedOWSDATE

Both of these output exactly the same format.

I ran into exactly the same problem when trying to work with user accounts (say, show the person who last edited a document, or wrote a blog post).

With Person fields the formatting appears to always output the Display Name of the user account (e.g. "Martin Hatch"). Again this was identical for:

  • Author
  • AuthorOWSUSER
  • DisplayAuthor

I basically want to have more control over how these values are output and formatted. In the case of date fields I want to reformat the date (which I'm sure I could work out using substring functions then and converting it to a date object, but that seems FAR too messy for me).

For the user field I really want the login name (or ideally their profile picture) but with just the display name there is very little I can do with it.

Any ideas? How on earth do these property mapping values get formatted?

3 Answers 3

3

You can override rendering of different field formats, have a look here http://blog.jussipalo.com/2013/03/sharepoint-2013-overriding-value.html

0

Welcome to SharePoint StackExchange!

If you set the webpart to render server side, you can control the formatting with xslt.

RenderOnServer=true

You can then format dates and things as you need them:

<xsl:value-of select="ddwrt:FormatDate(@Created, 1033, 2)"/>

This will do a short date with a time for example.

As for the usernames, I don't think that anything other that what is stored is accessible. The value which would be stored is the user id and the display name only I think. I will take a look and amend this if I am wrong.

HTH

9
  • Ok, good to know about the RenderOnServer property. Annoying though as I don't want to throw away all of the DisplayTemplate / JS goodness and return back to XSLT if I don't have to Commented Feb 5, 2013 at 13:06
  • Well, the other option would be to grab the property post render and reformat it in JS, wouldn't be to to hard to do. You could also transform the username that way also I guess.
    – Hugh Wood
    Commented Feb 5, 2013 at 13:49
  • The User profile service requires <domain>\<username> .. no way to get that from displayName afaik .. or is there? Commented Feb 5, 2013 at 14:00
  • 3 ways to do it: People picker, Search API or Query AD. SO from JS it would be using SPServices.js to do a search api query for 'PEOPLE' and 'DISPLAY NAME' I think.
    – Hugh Wood
    Commented Feb 5, 2013 at 14:15
  • .. and lets just hope you don't have two "John Smith" or "Jane Doe" in your profile database .. ? Commented Feb 5, 2013 at 14:22
0

First thing I would suggest is to check what do you get from search as the values for Author and Created managed properties. Probably, an easiest way to do it is REST search api. Say, you added an item named 'qwerty' to a list, and you crawled it. This is how you can get the value of Author and Created managed properties:

http://myServer/sites/mySite/_api/search/query?Querytext='qwerty'&SelectProperties='Author,Created'

Now, if you inspect the values for Author and Created, you would see that Author contains only display name of a user, and Created contains a string in specific date/time format.

If you are not satisfied with what value is stored in Author managed property, you can do the following:

  • Create site column of type 'Person or Group' and name 'MyUser'
  • Add site column to the list with your item
  • Add value for list item manually
  • Crawl
  • The value of user will be available in property 'MyUserOWSUSER' and should contain more than just display name

You can still change rendering of any values shown by Content Search web-part via client-side rendering with Display Templates (you don't necessarily need to use server-side rendering). I believe that Display Templates is an easier option than XSLT (but that's just my point of view).

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.