This project is read-only.

Shaping a collection of items

Topics: Core, Customizing Orchard, General, Troubleshooting
Oct 28, 2013 at 12:32 PM
So I decided to try to create a Carousel thingy on my own to learn shaping in Orchard better.

I wan't to be able to define items that have a image and a body to be rendered as a Carousel (media slide) type object.

I tried two different versions but always had some problems I had a hard time solving.

Both of the involved creating a custom Content Type I callled CarouselItem. This content had a Body_part (wow just figured how that sounds) and a MediaLibraryPicker field (I wish I could define it too only hold a single image, is there a image field in any module).

Now one solution was to create a projection query of these objects and use a Shape layout. I defined the shape Carousel and orchard picks it up. Now here I get stuck because I have a hard time understanding how to locate and define all the different parts of the content item because of this dynamic type. I had trouble doing something simple as counting how many objects I have in the query (it looks like it's iterating) and I have some really weird experience with the buildshapes method.

( I did a var shapes = Model.Buildshapes(); expecting to get a IEnumerable of objects because buildshapes is a Func<IEnumerable<objects>> instead it's like my variable is also a Func<IEnumerable<objects>> calling it again gives me a iterator so it seems I can't call count or cast it ToList() to get a number of instances.)

Even if I could count I'm not sure how I locate my Media field or body_part from the Model. I've tried to find a example of a simple shape being used in praxis but to no avail.

The second version was to just create a Container so I changed CarouselItem to containable and created a container (I find it weird that you have to define a container Content Type but you don't define what it's holding except in each instance). Someone suggested how I could do this and tried his version. First off he had the alternate shape for the container as widget-"containerContentType" so in my example it should be widget-carouselcontainer but that is not listed as a available shape name. Actually container widgets don't seem to care at all what ContentType their container is.

Also in his example he could access in what seemed like a strongly typed way his parts and fields straight off each contained item like this ContentItem.MediaLibraryField.Image[0] (this is off the top off my head).

I haven't got anything close to this type of control over my Content Types.

As I'm writing this I'm thinking that perhaps his Content Types are declared programatically and not in the Dashboard.

So if someone could give me a pointer, perhaps a guide where there are actual examples of shapes being used in a scenario or just suggestions why I seem to have a different objects from the guy that gave me his example.
Oct 28, 2013 at 2:14 PM
Edited Oct 28, 2013 at 2:35 PM
I am using this related to this pb with adapted templates in my own theme, if this could help.
Oct 28, 2013 at 5:37 PM
You can configure the media library field to take a single image. Just open up its configuration from the content type editor.
Nov 21, 2013 at 4:20 PM
CSADNT wrote:
I am using this related to this pb with adapted templates in my own theme, if this could help.
Thank you for your samples, bscarouselprojection was very helpfull for me.
Nov 21, 2013 at 8:42 PM
You are welcome :)