How to include custom term fields in summary view

Jul 4, 2011 at 6:05 PM

I posted a version of this question on SO here

I'm trying to figure out how to include a term's custom fields when it's displaying in summary view as taxonomyField attached to another contentItem.

I've got a taxonomy called Features and it's ContentType Feature Term to which I've added an ImageField

I also have a ContentType of Product which has a TaxonomyField called Features.

So here is a summary of my setup.

  1. Features Taxonomy - Vocabulary: f1,f2,f3,f4
  2. ContentTypes
    1. Feature Term - Fields: MyImage (Image)
    2. Product - Fields: MyFeatures (Taxonomy: Features)

If I navigate to ~/features/f1 I see the image listed along with it's title.

But if I navigate to ~/product-1, I only see the title of the feature but not the image.

How can I get FeatureTerm.Image to show up on the product's detail view along with FeatureTerm.Title?

I've tried playing around with the file but haven't had any luck. What ContentType would I be filtering for?  Product, Taxonomy, Feature?  I've successfully gotten to all of these but don't know what to do now.

<Match ContentType="Product">
    <Match DisplayType="Detail">
      <Place Fields_Contrib_TaxonomyField="Header:before" />
  <Match ContentType="Taxonomy">
      <Place Fields_Contrib_Image="Header:before"  />
  <Match ContentType="Features">
      <Place Fields_Contrib_Image="Header:before"  />

I've also tried playing around with Fields.Contrib.TaxonomyField-MyFeatures.cshtml but don't know what do with that either.

    var terms = (IEnumerable<Contrib.Taxonomies.Models.TermPart>)Model.Terms;
	string name = @Model.ContentField.Name;
    Contrib.Taxonomies.Models.TermPart term;

<!-- 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()) ))

<!-- New Code -->
@if (Model.Terms.Count > 0)
        @foreach (var myTerm in terms)
            foreach (var part in myTerm.ContentItem.Parts)

Jul 4, 2011 at 6:08 PM
Edited Jul 5, 2011 at 12:13 AM

Here is my export file i trimmed down if that helps.



<!--Exported from Orchard-->
      <Taxonomy DisplayName="Taxonomy">
        <TaxonomyPart />
        <CommonPart />
        <RoutePart />
      <Features TaxonomyId="24" DisplayName="Features Term">
        <TermPart />
        <RoutePart />
        <CommonPart DateEditorSettings.ShowDateEditor="False" OwnerEditorSettings.ShowOwnerEditor="True" />
        <Features />
      <Product ContentTypeSettings.Creatable="True" ContentTypeSettings.Draftable="True" DisplayName="Product">
        <BodyPart BodyTypePartSettings.Flavor="html" />
        <CommonPart DateEditorSettings.ShowDateEditor="False" OwnerEditorSettings.ShowOwnerEditor="True" />
        <ContainablePart />
        <Product />
        <RoutePart />
      <TaxonomyPart />
      <TermPart />
      <Features ContentPartSettings.Attachable="True">
        <TermImage.ImageField />
      <Product ContentPartSettings.Attachable="True">
        <MyFeatures.TaxonomyField ImageFieldSettings.MaxHeight="0" ImageFieldSettings.MaxWidth="0" ImageFieldSettings.Required="False" ImageFieldSettings.AlternateText="False" ImageFieldSettings.ResizeAction="Validate" TaxonomyFieldSettings.TaxonomyId="24" TaxonomyFieldSettings.LeavesOnly="False" TaxonomyFieldSettings.SingleChoice="False" />
    <Taxonomy Id="/Route.Slug=features" Status="Published">
      <CommonPart Owner="/User.UserName=admin" CreatedUtc="2011-07-04T15:46:33Z" PublishedUtc="2011-07-04T15:46:33Z" ModifiedUtc="2011-07-04T15:46:33Z" />
      <RoutePart Title="Features" Slug="features" Path="features" />
    <Features Id="/Route.Slug=fire-proof" Status="Published">
      <ImageField.TermImage FileName="~/Media/Default/Features/TermImage/all-climate-1.jpg" Height="100" Width="100" />
      <CommonPart Owner="/User.UserName=admin" Container="/Route.Slug=features" CreatedUtc="2011-07-04T15:46:56Z" PublishedUtc="2011-07-04T15:46:56Z" ModifiedUtc="2011-07-04T16:29:34Z" />
      <RoutePart Title="Fire Proof" Slug="fire-proof" Path="features/fire-proof" />
    <Features Id="/Route.Slug=long-lasting" Status="Published">
      <ImageField.TermImage FileName="~/Media/Default/Features/TermImage/deep-cycle-1.jpg" Height="100" Width="100" />
      <CommonPart Owner="/User.UserName=admin" Container="/Route.Slug=features" CreatedUtc="2011-07-04T15:47:06Z" PublishedUtc="2011-07-04T15:47:06Z" ModifiedUtc="2011-07-04T16:29:42Z" />
      <RoutePart Title="Long Lasting" Slug="long-lasting" Path="features/long-lasting" />
    <Features Id="/Route.Slug=underwater" Status="Published">
      <ImageField.TermImage FileName="~/Media/Default/Features/TermImage/reserve-cap-1.jpg" Height="100" Width="100" />
      <CommonPart Owner="/User.UserName=admin" Container="/Route.Slug=features" CreatedUtc="2011-07-04T15:47:19Z" PublishedUtc="2011-07-04T15:47:19Z" ModifiedUtc="2011-07-04T16:29:49Z" />
      <RoutePart Title="Underwater" Slug="underwater" Path="features/underwater" />
    <Features Id="/Route.Slug=organic" Status="Published">
      <ImageField.TermImage FileName="~/Media/Default/Features/TermImage/spiral-wound-1.jpg" Height="100" Width="100" />
      <CommonPart Owner="/User.UserName=admin" Container="/Route.Slug=features" CreatedUtc="2011-07-04T15:47:26Z" PublishedUtc="2011-07-04T15:47:26Z" ModifiedUtc="2011-07-04T16:29:57Z" />
      <RoutePart Title="Organic" Slug="organic" Path="features/organic" />
    <Product Id="/Route.Slug=product-1" Status="Published">
      <BodyPart Text="&lt;p&gt;Product 1 Body&lt;/p&gt;" />
      <CommonPart Owner="/User.UserName=admin" Container="/Route.Slug=products" CreatedUtc="2011-07-04T15:49:48Z" PublishedUtc="2011-07-04T15:53:45Z" ModifiedUtc="2011-07-04T15:50:34Z" />
      <RoutePart Title="Product 1" Slug="product-1" Path="product-1" />
    <Product Id="/Route.Slug=product-2" Status="Published">
      <BodyPart Text="&lt;p&gt;Prod 2 body&lt;/p&gt;" />
      <CommonPart Owner="/User.UserName=admin" Container="/Route.Slug=products" CreatedUtc="2011-07-04T15:50:51Z" PublishedUtc="2011-07-04T15:53:45Z" ModifiedUtc="2011-07-04T15:50:57Z" />
      <RoutePart Title="Product 2" Slug="product-2" Path="product-2" />
Jul 5, 2011 at 6:49 PM

I think you can achieve what you want by creating the file Fields.Contrib.TaxonomyField-MyFeatures.cshtml like you already tried.

@if (Model.Terms.Count > 0) {
  @foreach (var term in Model.Terms) {
    var contentItem = term.ContentItem; // very important
    @contentItem.FeatureTerm.MyImage.FileName // the image filename

Whatever, you should be able to see this property in the shape tracing.

Jul 6, 2011 at 5:41 AM

Thanks for the help!  As usually, it was a double whammy.  First I was using the "terms" enumeration copied from the default view:


var terms = (IEnumerable<Contrib.Taxonomies.Models.TermPart>)Model.Terms;


So that wasn't helping any.  

Once I correctly switch to your @foreach(var term in Model.Terms) the following gave me the path.




which I wrapped like so....


var contentField = myTerm.ContentItem.Features.TermImage;
<p class="image-field">
  <img src="@Url.Content(contentField.FileName)" alt="@contentField.AlternateText" width="@contentField.Width" height="@contentField.Height"/>


The real bugger was that when you go that deep in shape tracing the only thing it shows is the id.  :(    Thanks for the help!