This project is read-only.

create Alternate generated from code?

Topics: Customizing Orchard
Feb 24, 2012 at 5:48 AM

Hi all, Is there some nice way to get a copy [using shape tracing or the likes] of a shape that is generated via code; basically so I can create an Alternate. Practically, I wish to add an image to: Orchard.Core.Shapes.CoreShapes::List   Any ideas or dead-cert way to achieve such? Thanks Dyr

Feb 24, 2012 at 6:07 AM

Not sure what you're asking: all alternates are created from code.

Feb 24, 2012 at 8:49 AM

Ahhh, well that clears that up then – I suppose I must mean ‘overriding’ – not sure of the term, but I’ve currently got a view called ‘list’ to replace the default shape, but was wanting to know if there was a way to grab the original code from the default shape instead of reinventing the wheel; as most of it I want? Thanks Dyr

Feb 24, 2012 at 9:06 AM

When you create an alternate from shape tracing, it will copy over the code for the base shape to the new template, unless (as is the case of List) it's a shape method and not a template. In that case you're on your own, unless somebody wrote a blog post such as this: or this

Feb 24, 2012 at 9:56 PM

Haha, brilliant work as per usual mate, and exactly what I was after. Thanks Dyr

Feb 27, 2012 at 4:20 AM

Hmm, not as straight forward as I thought, I really can't work out how to gather the list items for my view - as in:

    IEnumerable<dynamic> ListItems = Model.*....*?;

I have been through the trace - what a maze - but I'm truly lost as to what the reference should be? All my attempts return null? Sorry, I thought it was going to be fairly simple with your blog as a guide. Thanks Dyr.

Feb 27, 2012 at 4:39 AM

I'm confused. It's in the posts:

    var list = Model.ContentItems;
    var items = list.Items;


Feb 27, 2012 at 7:00 AM
Edited Feb 27, 2012 at 7:01 AM

Thanks for your assistance. I'll start from the start - basically im getting the same result as 'ejsa13' got on your blog, we assume it's because we're using your code with a generic list and not a blog? The error being:

The type arguments for method 'System.Web.Mvc.TagBuilder.MergeAttributes<TKey,TValue>(System.Collections.Generic.IDictionary<TKey,TValue>, bool)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

Thrown at:

var listTag = Tag(list, "ul" );

Of which you responded:
Attach a debugger and look at that list variable. I wouldn't be surprised if it was null.

Which I have done and discovered that the 'list' isn't null, but appears to hold a whole lot of orchard data [(list).ClaySharp.IClayBehaviorProvider.Behavior etc. etc.], but not of the type we're after?  Any thoughts as to what maybe different? Thanks again, Dyr

Feb 27, 2012 at 7:44 AM

That is an completely different question. That error message is fairly explicit, it asks you to cast that list object to something it can recognize, I think.

Feb 27, 2012 at 10:54 AM

this is where it breaks:

tagBuilder.MergeAttributes(shape.Attributes, false);

is it implying the compiler doesnt know what it is dealing with and needs to be explicitly told?  I've seen with similar errors that specifying generic parameters in the method call can aid the compiler?  I've a bad feeling this is way above my head...any thoughts? Cheers Dyr

Feb 28, 2012 at 12:52 AM

I tried exactly the same thing with the same error, Im not far into orchard development and before pursuing a remedy for this I thought I would wait for 1.4. Does anyone know if things change much in this regard, or more than likely, a solution will still need to be sought irrespective of version?

Feb 28, 2012 at 5:19 AM

Yes, the compiler needs to be explicitly told what to expect here, for example by casting it. This won't change in 1.4 (it can't: this has to do with how the C# compiler deals with dynamics).

Feb 28, 2012 at 6:18 AM

I see, I understand the principal of casting, but I dont know how to discover what type in this case I should cast to?

    var list = Model.ContentItems;
    var items = list.Items;
    var count = items.Count;
    var listTag = Tag(list, "ul");
    var index = 0;
Thanks for your time, RC.
Feb 28, 2012 at 7:33 AM

If you're in the context of a list template, Model.ContentItems is probably not what you want to pass into Tag. Maybe Model directly?

Feb 29, 2012 at 2:02 AM

Yeah, I tried that originally in conjunction with shape tracing to go through the models contents to see what the correct approach would be, but became completely lost with the vast amount of unrequited [orchard] data?  @Dyrgutt - did you ever get his working? Thanks RC

Mar 1, 2012 at 2:13 AM

Hi RedCrom, afraid not - I've been busy trying to catch up on design work [I only *attempt* programming when I can afford to].  My thoughts much like yours was to debug the orginal List shape code to try and better understand what is happening, though as per one of my older posts, I cant for the life of me workout how to debug orchard core? Sorry to be utterly useless, this has stumped me as well. Goodluck!