Getting a reference to a module in a theme view.

Topics: General
Nov 29, 2012 at 4:10 PM

Hi Chaps.

I've got a Projection Widget in which I want to show, amongst others, a Taxonomy Field.

I've used a Query with a Grid Layout and Properties Display Mode but there are no Tokens available to list my Taxonomy Field.

I don't want to change my overridden Summary view and there are no alternative Alternates (:P available so I've created a custom view and set the Grid Display Type to it.

So far so good except how to get at the Taxonomy data?

I Google to this: and tried the suggestions but I can't get a reference to Contrib.Taxonomies.

I've added a reference to the dll from AppData\Dependencies to no avail.

What am I missing?


Nov 29, 2012 at 5:48 PM

The reference should be to the project, not to the dll.

Nov 29, 2012 at 7:00 PM

Hi Bertrand.

Do you mean I have to create a module to achieve this?

Nov 30, 2012 at 4:32 PM

You said "I've added a reference to the dll from AppData\Dependencies to no avail.". What did you add a reference to if you don't already have created a module??

Nov 30, 2012 at 7:04 PM

OK. I didn't realise that my Theme needed to be a VS Project so I've recreated it, got the reference etc. but the issue is the same only with Intellisense!

I'm guessing that my original view was resolving Contrib.Taxonomies (at runtime), but I can't work out how to access the terms. I've copied the the code from the Taxonomies view (sorry I can't be explicit with the name but I've not got my project in front of me) that appears in Shape Tracer but I've not been able extract the terms from the Model.

Dec 1, 2012 at 5:48 AM

Yeah, it's a little difficult to be of any help with that level of detail, I'm sorry.

Dec 1, 2012 at 2:45 PM

I see what you mean.

Back to the begining:

I have a Projection that querys a Content Type called Article. I already have an Alternate called Content-Article.Summary.cshtml which I don't want to change.

I've created another view called Content-Article.Tile.cshtml and entered "Tile" into the Grid Display Type. Here's the code:

@using Orchard.Utility.Extensions;
@using Orchard.ContentManagement;
@using Orchard.Core.Containers.Models;
  ContentItem item = Model.ContentItem;
  Orchard.ContentManagement.ContentItem contentItem = Model.ContentItem;
  string url = Model.ContentItem.Article.Picture.Url;
  url = url.Substring(2);

When it's rendered I get Content-Article.Tile with Content-Article.Summary inside it. Not what I want. Removing @Display(Model.Content) gets rid of the content from Content-Article.Summary but it's required in order to render Fields.Contrib.TaxonomyField.cshtml. Ideally I want to insert something like the code in Fields.Contrib.TaxonomyField.cshtml but I've no idea where to start with that.

Dec 2, 2012 at 3:35 PM

Got there in the end:

	Orchard.ContentManagement.Utilities.LazyField<System.Collections.Generic.IEnumerable<Contrib.Taxonomies.Models.TermPart>> terms = Model.ContentItem.Article.Zone.Terms;
 @(new HtmlString( string.Join(", ", terms.Value.Select(t => Html.ItemDisplayLink(t.Name, t.ContentItem ).ToString()).ToArray()) ))
Dec 2, 2012 at 11:14 PM

Do you still need help with this?

Dec 3, 2012 at 10:21 AM

I guess not, unless there is a way of aquiring a reference to Model.ContentItem.Article.Zone.Terms using a dynamic query, which might be preferable?

I've a couple of observations to offer, tho':

I've just started using Projections and they offer significant advantages over other containers in as much as they don't require content editors to know/remember which Container they need to add their content to, and as we all know, as far as users are concerned, more to think about, more to be unhappy about.

The option of using an alternate view in the Query - Display Mode is a very attractive option. Although Properties Mode is pretty darn versatile, it has limitations and my preference would always lean towards using a view to determine which properties of the Model to render.

Given that the approach I've used caused some unexpected behaviour when invoking @Display(Model.Content), could that be considered a bug, or am I using an 'Unsupported Feature'?

Dec 3, 2012 at 7:09 PM

I don't know. What unexpected behavior?