Order display of Content Parts having the same type

Topics: Customizing Orchard, General
Mar 3, 2012 at 6:08 AM

Is there a way to control the display of Content Parts of the same type in the front end?

Placement.info gives the power to order Content Parts according to group types (i.e: positioning Text fields first, then numeric fields, then Boolean Fields); however, suppose I have 5 text fields (Fields_Common_Text) that I would like to control their display position individual, then that would be a different story. Unless perhaps I'm missing something and Placement.info can do that as well???

Coordinator
Mar 3, 2012 at 7:50 AM

It's all explained here: http://docs.orchardproject.net/Documentation/Understanding-placement-info#"Place"Element

Mar 3, 2012 at 1:25 PM

Bertrand, thanks for the tip, I already read it a while ago, but I had to go over a second time to spot my solution

Quote:

the following placement will suppress the display of text fields named "Occupation":

<Place Fields_Common_Text-Occupation="-"/>
Mar 4, 2012 at 1:15 AM

Can you not do this with numeric and datetime fields?  I was able to do it with the common_text field but I'm having trouble with the numeric and datetime fields.

I tried the following:

<Place Fields_Numeric-Deposit="Meta:3"/>
<Place Fields_DateTime-AvailableDate="Content:3"/>

For some reason it's not working. I've triple checked my field names to make sure they are correct and they are.

Developer
Mar 4, 2012 at 9:19 AM

Looks like we forgot to provide a differentiator:

 protected override DriverResult Display(ContentPart part, Fields.DateTimeField field, string displayType, dynamic shapeHelper) {
            return ContentShape("Fields_DateTime", // Differentiator should be specified here
                () => {
                    var settings = field.PartFieldDefinition.Settings.GetModel<DateTimeFieldSettings>();
                    var value = field.DateTime;

                    var viewModel = new DateTimeFieldViewModel {
                        Name = field.DisplayName,
                        Date = value != DateTime.MinValue ? value.ToLocalTime().ToShortDateString() : String.Empty,
                        Time = value != DateTime.MinValue ? value.ToLocalTime().ToShortTimeString() : String.Empty,
                        ShowDate = settings.Display == DateTimeFieldDisplays.DateAndTime || settings.Display == DateTimeFieldDisplays.DateOnly,
                        ShowTime = settings.Display == DateTimeFieldDisplays.DateAndTime || settings.Display == DateTimeFieldDisplays.TimeOnly,
                        Hint = settings.Hint,
                        Required = settings.Required
                    };

                    return shapeHelper.Fields_DateTime( // this is the actual Shape which will be resolved (Fields/DateTime.cshtml)
                        Model: viewModel);
                }
            );
        }

 

Developer
Mar 4, 2012 at 9:22 AM

You could try it out by modifying DateTimeFieldDriver.cs (in Orchard.Fields):

private string GetDifferentiator(DateTimeField field, ContentPart part)
        {
            return field.Name;
        }

        protected override DriverResult Display(ContentPart part, Fields.DateTimeField field, string displayType, dynamic shapeHelper) {
            return ContentShape("Fields_DateTime", 
                GetDifferentiator(field, part),
                () => {
                    var settings = field.PartFieldDefinition.Settings.GetModel<DateTimeFieldSettings>();
                    var value = field.DateTime;

                    var viewModel = new DateTimeFieldViewModel {
                        Name = field.DisplayName,
                        Date = value != DateTime.MinValue ? value.ToLocalTime().ToShortDateString() : String.Empty,
                        Time = value != DateTime.MinValue ? value.ToLocalTime().ToShortTimeString() : String.Empty,
                        ShowDate = settings.Display == DateTimeFieldDisplays.DateAndTime || settings.Display == DateTimeFieldDisplays.DateOnly,
                        ShowTime = settings.Display == DateTimeFieldDisplays.DateAndTime || settings.Display == DateTimeFieldDisplays.TimeOnly,
                        Hint = settings.Hint,
                        Required = settings.Required
                    };

                    return shapeHelper.Fields_DateTime( // this is the actual Shape which will be resolved (Fields/DateTime.cshtml)
                        Model: viewModel);
                }
            );
        }

If that works, you could file a bug (or provide a patch yourself)

Mar 4, 2012 at 9:31 AM

Yea that was it. I added the call to the differentiator function in the ContentShape parameter and it worked. Thanks!

Coordinator
Aug 28, 2012 at 6:14 AM

For what it's worth, I hit upon the same bug and push a fix into 1.6 for it. A bug should have been filed for this ;)