Orchard CMS: How to display different views for summary and detail display type of Tags_ShowTags shape?

StackOverflow https://stackoverflow.com/questions/23670998

  •  23-07-2023
  •  | 
  •  

Question

I need to display different views for summary and detail display type for TagsPart, but it contains only one shape Tags_ShowTags for both views.

protected override DriverResult Display(TagsPart part, string displayType, dynamic shapeHelper) {
    return ContentShape("Parts_Tags_ShowTags",
        () => shapeHelper.Parts_Tags_ShowTags(Tags: part.CurrentTags.Select(x => new ShowTagViewModel { TagName = x })));
}

Is there way to create different views for shape Tags_ShowTags? Like this: Tags.ShowTags-MyContentType.Detail.cshtml Tags.ShowTags-MyContentType.Summary.cshtml

Was it helpful?

Solution

Marco Serralheiro's tip to use Atlernates allows to use different views for summary and detail display type without creating extra shapes. See following example:

<Match ContentType="MyContentType">
  <Match DisplayType="Summary">
    <Place Parts_Tags_ShowTags="Content:4;Alternate=Parts_Tags_ShowTag_MyContentType_Summary"/>
  </Match>
  <Match DisplayType="Detail">
    <Place Parts_Tags_ShowTags="Content:4;Alternate=Parts_Tags_ShowTag_MyContentType_Detail"/>
  </Match>
</Match>

View names:

/Views/Parts.Tags.ShowTag.MyContentType.Summary.cshtm
/Views/Parts.Tags.ShowTag.MyContentType.Detail.cshtml

OTHER TIPS

Yes. Have you tried the Shape Tracing tool, to find what are the available alternates for that shape (http://docs.orchardproject.net/Documentation/Customizing-Orchard-using-Designer-Helper-Tools)? You can also take a look at http://docs.orchardproject.net/Documentation/Alternates - Parts_Tags_ShowTags is used as example to explain alternates.

Edit:

I managed to increase the number of available alternates (that are available without the need to explicitly designate them in the placement.info file) following this tip: http://kobowi.co.uk/blog/2012/11/content-display-type-alternates-for-content-parts-in-orchard

In my own module I placed this "PartContentTypeAlternateFactory.cs":

using Orchard.DisplayManagement.Implementation;
using System;

namespace MyModule.Name {
    public class PartContentTypeAlternateFactory : ShapeDisplayEvents {
        public override void Displaying(ShapeDisplayingContext context) {
            context.ShapeMetadata.OnDisplaying(displayedContext => {

                var shapeType = displayedContext.ShapeMetadata.Type;
                var contentItem = displayedContext.Shape.ContentItem;

                if (contentItem == null) return;

                var displayType = displayedContext.ShapeMetadata.DisplayType;
                var contentType = contentItem.ContentType;

                // add a couple more alternates
                displayedContext.ShapeMetadata.Alternates.Add(
                    String.Format("{0}__{1}", shapeType, displayType));
                displayedContext.ShapeMetadata.Alternates.Add(
                    String.Format("{0}__{1}__{2}", shapeType, (string)contentType, displayType));
            });
        }
    }
}

This gives me a few more alternates to chose from, "out of the box". They even show up in the Shape Tracing tool, and one can use it to create the appropriate cshtml files.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top