Orchard - How to display custom Term fields in a taxonomy field?

I have a contentType (product) that has a taxonomy (function) field. The term taxonomy (product function term) has been configured to include the image field and description field.

I would like the product detail view to display an image with the name along with the name, but I cannot find it for access.

I created the following:

Taxonomy

  • Commodity System
    • Dictionary: Feat1, Feat2, Feat3

ContentTypes

  1. Product

    • Fields: Features (taxonomy)
  2. Product Features Duration

    • Fields: Description (HTML), Image (Image)

representation

Fields.Contrib.TaxonomyField-Features.cshtml

<!-- Old Code --> @if (Model.Terms.Count > 0) { <p class="taxonomy-field"> <span class="name">@name.CamelFriendly():</span> @(new HtmlString( string.Join(", ", terms.Select(t => Html.ItemDisplayLink(Html.Encode(t.Name), t.ContentItem ).ToString()).ToArray()) )) </p> } <!-- New Code --> @if (Model.Terms.Count > 0) { <div> @foreach (var myTerm in Model.Terms) { @Display(???) } </div> } 

What replace question marks? I thought it would be myTerm.Image, but this field does not exist in the dynamic object.

I attached the image of the designer.

enter image description here

+4
source share
2 answers

How Sebastien helped me figure out http://orchardtaxonomies.codeplex.com/discussions/263844

Below is the work.

(key bit: contentField = myTerm.ContentItem.Features.TermImage; )

 @foreach (var myTerm in Model.Terms) { var contentField = myTerm.ContentItem.Features.TermImage; if (!String.IsNullOrWhiteSpace(contentField.FileName)) { <p class="image-field"> <img src="@Url.Content(contentField.FileName)" alt="@contentField.AlternateText" width="@contentField.Width" height="@contentField.Height"/> </p> } } 
+1
source

If you want to use the current dev branch in the module, you can access the "Parameters" section of the content elements, which will lead you to all the terms that are currently in use.

If you are using version 0.9 of the module, then you can dynamically access the fields by receiving a link to your content element, and then create the file contentItem.PARTNAME.FIELDNAME. In the case of the type named Product and the name of the Feature field, this will be contentItem.Product.Feature. Then, if this term has a property called Image, it will be termContentItem.ProductTerm.Image.

I need more information to give you the exact syntax like field type, exact name of content types. Or you can post a question on the codeplex module project discussion forum.

+4
source

All Articles