I'm adding a thumbnail custom field to the documents and files part of Sitefinity (8.1) and then creating a new widget template to display them. So far so good but I don't know how to get my custom field in my new razor view.
Here's what I did so far:
1. Added a new custom field to the documents and files called "Thumbnail" and set it to be an image
2. Modified a document and set the field to be an image in my system.
3. Copied the MVC/Views/DocumentsList/List.DocumentsList.cshtml to my own view (List.DocumentsGrid.cshtml) in the ResourcePackages folder
4. Dropped the document list widget on a page and set the view to my DocumentsGrid view
Everything renders fine but I'm trying to use the new custom field called Thumbnail. I thought it would be simple (ha) so I could do this:
But that isn't rendering anything.
I can't seem to find any example where this is done. Anyone know how to access a custom field in a custom view?
This looks good but something is amiss because the @item.Fields.Thumbnail field is always null and not working.
I've checked the custom field and it looks right. I don't seem to have any tools in the view to be able to figure out what fields are available (like a debug dump of the fields) and without building an entire widget or something I'm not sure how to debug something like this?
I've called the field "Thumbnail" and made it of type Related Media. Attached are the settings for my custom field. Looks okay to me but am I missing something?
Just a note I actually submitted a ticket to get this resolved as it didn't make sense and wasn't working for me.
Turns out that I was using a field named "Thumbnail" and there's already a field called Thumbnail in the documents but it's not serializeable and doesn't appear in the backend UI. When you create a field with the same name it overrides the default one, but that field wasn't serializeable (like the original one) and was causing the lookup to fail.
Simply renaming my field to something like Preview resolved the issue and everything works perfectly now.
Did you have to add or change the namespace or model for the template for this to work?
<img src="@item.Fields.PDFThumbnail.Fields.MediaUrl" />