Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Use ctx.CurrentItem.FileRef in DispForm

$
0
0

Hi all,
I'd like to customize a document library display form to show the file if it's a jpg.

I can do it in the list view but not in the display form, the ctx.CurrentItem.FileRef and the ctx.CurrentItem.File_x0020_Type are Undefined.

(function() {
    var overrideCtx = {};
    overrideCtx.Templates = {};
    overrideCtx.Templates.Fields = {
        'Description': {
            'DisplayForm': customDisplayField,
            'View': overrideFieldTemplate
      }
    };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();

function customDisplayField(ctx) {
    return "<img src='" + fileRef + "' style='max-width:200px;'/>";
}
function overrideFieldTemplate(ctx) {

    if (ctx.CurrentItem.File_x0020_Type === "jpg") {
        return "<img src='" + ctx.CurrentItem.FileRef + "' style='max-width:200px;'/>";
    }
    else {
        return "<i>no preview available</i>";
    }
}

Is there a way to retrieve the file path and extension in the display form?
I know that can be a silly question but I'm really new to jsLink, I've started just yesterday.

thankyou
Cinzia




Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>