Sep 20, 2012 at 4:24 PM
Edited Sep 20, 2012 at 4:25 PM
I'm pretty new in Orchard land but I like this CMS already very much - as an Author at least, it's great to see a .NET based CMS with so many extensions and templates available.
As a developer, I'm just started learning but I'm about to pull my hair out because I'm struggling already at things that seem to me like the most basic tasks.
I added a new Field to the HtmlWidget Content Type. It should be a Link because I want to make headers (titles) of HtmlWidgets linkable. For testing purposes, I now use just a simple text field called "TestText" for debugging.
So I edited Widget.Wrapper.cshtml where the Title is rendered to do something with this new field there. I struggled to find good and current doc on how to access fields from code (found a lot about fields that are part of PARTS but not about simple fields
I add directly to a ContentType).
Well, after some investigations and debugging it turns out those fields are at runtime part of the ContentPart.
I found out by doing some LINQ like this:
var obj2 = ((Orchard.ContentManagement.ContentItem)Model.ContentItem).Parts.Where(p => p.Fields.Any(f => f.Name == "TestText")).FirstOrDefault();
So a ContentPart was found here and I thought I found the solution. I didn't. The first try, which, by documentation, is rather old syntax from 1.0 days, failed:
var contentPart = ((IContent)Model.ContentItem).As<ContentPart>();
var testText = contentPart.Fields.First(f => f.Name == "TestText").Storage.Get<string>(null);
It crashes and tells me that the sequence contains no elements. I really don't get it because my earlier query indicated clearly that this field is contained in the ContentPart.
Anyway, I tried, according to documentation, the newer syntax:
var testText = Model.ContentItem.ContentPart.TestText.Value;
This also crashed telling me that there is no TestText property on ContentPart.
I really don't get it and it may very well be because I have to few understanding of the core concepts of Orchard yet, but hopefully someone can help me out here.
Thank you very much in advance for any help!