Wednesday, March 26, 2014

Custom Display Template for Content Search

I am using the web part "Content Search" to display the news. But I would like to make some modifications to the Display template "Large" that I am using. First, I would like to change the arrows that is used for the paging control. Then the images should be wider and I want another managed property to be displayed in the rollup. To do this, I have to create a copy of the display templates and modify it in an HTML editor.

There are two types of display templates. One that is prefixed with "Control" that controls the layout of the entire web part, like paging controls and such. The other one is prefixed with "Item" and is used to control the items that are rolled up in the web part. These display templates are independent of each other, but since I want to change both the layout of the entire control and each item, then I need to make a copy of these both html files.

Map the following URL to a network drive: http://yourSPserver/_catalogs/masterpage

Then open folder Display Templates > Content Web Parts

Note: Only copy the Control and Item html files,  the .js files are created automatically!

I copied the control file Control_ListWithPaging.html and named it Custom_Control_ListPaging. And then I copied the item Item_LargePicture.html and named it Custom_Item_LargePicture.
Note: Refresh the folder and note that the .js files are created:


Modify the Custom_Control_ListPaging.html

Give the file a proper Title, in this case "Custom List with Paging":


It will be displayed with that Title in the web part drop down under Display Templates in the web part:

I want to change the Paging icons, because they don’t look very nice:

The css classes needs to be changed inside the Control template, and modify the classes as you wish and refer to it from the new Control template. Might not be the most sexy buttons, but at least they look a bit more like my color theme on the site:

Modify the Custom_Item_LargePicture.html

I want to make images wider and add another third line in the web part so that I can display another field and that has to be done in the Item files. Open the Custom_Item_LargePicture.html and make the following changes:

Change the Title tag to something useful, so that it is displayed correctly in the dropdown list in the web part (same as above with the Control).

In the head, modify the mso:ManagedPropertyMapping: copy this code:

"'Line 2'{Line 2}:'Description'"

Change it to the below code, you can refer to any managed property you like (in this case Description) but it does not really matter since you can change it in the web part anyway:

"'Line 3'{Line 3}:'Description'"

This will add another line in the Property Mappings so that you can display a third line with a managed property in the web part (see "Line 3" below):



Then scroll down to the remarked js code and add a new variable after "Line 2" and name it to “Line3”. That is in the following places in the code::



Then change the markup also, add a new div:


I had to modify the css classes (by adding them to my own css stylesheet so they override the default ones) too to make the rows more aligned, since I added a third line. The result is:


Tuesday, March 25, 2014

Image Rendition and Blob Cache

I want to display my news in the Content Search Web Part. And use the one that displays 3 pictures on top and the text below them. But there are a few things I would like to change. One thing is to change the image size so that it fills the text area and still keeps the image in small size. To do this, I have to work with Image Rendition.

Under "Look & Feel" in the site administration, there is a setting called "Image Rendition". When click on that, it tells you that the blob cache is not yet configured:


Configure Blob Cache on the server:

Change the web.config file which is found in the inetpub folder for your site (similar path like C:\inetpub\wwwroot\wss\VirtualDirectories\80)

NOTE: Make a copy of the web.config before edit!

Go to the line that begins with “blob cache location"
Change the location attribute to specify a directory that has enough space to accommodate the cache size, typically a D or E drive (not the system drive!)
The size is expressed in gigabytes (GB), and 10 GB is the default. Do not set it to lower than that.
"BlobCache location="D:\BlobCache" path="\.(gif|jpg|jpeg|jpe|jfif|bmp|dib|tif|tiff|themedbmp|themedcss|themedgif|themedjpg|themedpng|ico|png|wdp|hdp|css|js|asf|avi|flv|m4v|mov|mp3|mp4|mpeg|mpg|rm|rmvb|wma|wmv|ogg|ogv|oga|webm|xap)$" maxSize="10" enabled="true"

Save the web.config file and the site will automatically recycle.

Now when you go back to “Image rendition” on the site, you can add a new item:


Give it a unique name, I just added the word “Custom” after and then set your own image sizes:

To see examples of how the rendition works, go to an Image library and select “Edit renditions” while hovering an image:


This will show how the image renders in the different ID’s:

 
Now I have to create a new Display Template for my Content Search Web part so that I can use this rendition, and that will be my next article.