Customize List Item Rendering

Topics: Customizing Orchard
May 17, 2011 at 7:44 PM

Hello,

i'm new to Orchard and at the moment i'm trying to get things done.

One of my problems is to customize the Rendering of a custom content type in a list. I've built a special "ImageGallery" ContentType of some standard parts, an ImageField and two TaxonomyFields. Basically everything works fine. Now I want to customize the rendering of my ListItem. I can access the Image- and Textfields without problems. When I try to render the Taxonomy-Fields in my Template, then I've no chance to access the Terms collection.

I've installed the Orchard Designer Tools to view my Model-Structure. There I realized that the field properties of both Taxonomy-Fields doesn't contains this Terms collection. How can I access those properties through my model? I know that I can render an alternative layout of my TaxonomyField, but I need it customized in my special view.

Best regards,

Ulf

Jul 7, 2011 at 3:57 PM

Hello uhillig,

Did you ever find a solution for this, I am facing the same problem as I have created a custom view for the list I am rendering but cannot access the taxonomy term. I can access the taxonomy as a TaxonomyField but this does not expose any properties for the TermPart?

Coordinator
Jul 7, 2011 at 6:57 PM

Does this discussion answer your problem ?

http://orchardtaxonomies.codeplex.com/discussions/263844#post637104

Jul 8, 2011 at 6:32 AM

Hi danmce,

Yes i found a solution, but I'm not sure if it the best solution.

Generally I've created a special summary view for my content type. In this view i iterate over the available shapes in Model.Content and try to find one shape with a Terms-collection. With this terms collection I'm able to render the Taxonomy parts the way i like.

It looks something like that:

        @foreach(var shape in Model.Content)
            {
                var terms = shape.Terms;
                
                if (terms != null)
                {
                    var count = 0;
                    <p>
                        <span>@shape.ContentField.Name: </span>
                        @foreach (Contrib.Taxonomies.Models.TermPart termPart in terms)
                        {
                            if (count > 0){
                                <span>, </span>
                            }
                            <span>@RenderTermPart(termPart)</span>
                            count = count + 1;
                        }
                    </p>
                }
            }

Hope this helps.

Best regards,

uhillig