0

In SharePoint 2013, inside my Style Library, I have a folder with 100 images. What must I do to display a preview of each image within this Style Library image directory, for each image that is in it, rather than just displaying links that open the image in a seperate tab?

So far, I made an attempt of creating a new standard view and added the image content type to the new view, but it doesn't display a preview of each image.

What must I do?

1

Assign a display template with below code to the view. I am displaying the preview in the 'Title' column. You can create a different column and update the code as needed. The 'Name' column has to be part of the view for this to work.

(function () {
    var titleFieldCtx = {};
    titleFieldCtx.Templates = {};
    titleFieldCtx.Templates.Fields = {
        "Title": { //
            "View": TitleFieldViewTemplate
        }
    };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(
        titleFieldCtx
    );

})();

function TitleFieldViewTemplate(ctx) {
    var item = ctx.CurrentItem;
    var validFileTypes = ['jpg', 'jpeg', 'png']; //Valid image file types
    if (validFileTypes.indexOf(item.File_x0020_Type) >= 0 && item.FileRef) {
        return "<img src='" + item.FileRef + "'"; //build the image html. Set the height and width as needed
    }
    else {
        return item.Title;
    }
}
0
  1. Change the property of the image and set the content type as Image
  2. Edit view and choose field Preview
  3. Save the view

This will add a new field to the view which basically gives a preview of the image

  • Doing this adds a column for 'Preview' but the where the preview image should be there is only a generic white icon. Any tips? Edit: Same result with 'Thumbnail Preview'. – AM2FTW Apr 26 '17 at 7:26
0

My quick and dirty approach is to open that library in Windows Explorer view, then changing the view to Thumbnails... and voila, you can preview all images.

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.