Cannot override templates

Jul 25, 2011 at 1:51 AM

I created a simple single level taxonomy, but I cannot override any of the templates.

The thing that gives it away is that if I run shape tracing, none of the Taxonomy templates are listed as alternates. What could this possibly mean? I am sure I have just missed something simple, but I followed the tutorial step by step.

Any help would be great, thanks.

Jul 25, 2011 at 1:30 PM

Enable the shape tracing tool in modules and use it to select a taxonomy element on one of your page and you will be able to create an alternate view of the taxonomy display template.

You can also do it manually in your current theme folder adding a file named Fields.Contrib.TaxonomyField.cshtml in the 'Views' folder and change the initial template :

 

@using Orchard.Utility.Extensions;
@using Orchard.ContentManagement;

@{
    var terms = (IEnumerable<Contrib.Taxonomies.Models.TermPart>)Model.Terms;
    string name = @Model.ContentField.Name;
}

@if (Model.Terms.Count > 0) {
<p class="taxonomy-field">
    <span class="name">@name.CamelFriendly():</span>
    @(new HtmlString( string.Join(", ", terms.Select(t => Html.ItemDisplayLink(Html.Encode(t.Name), t.ContentItem ).ToString()).ToArray()) ))
</p>
}

Aug 22, 2011 at 6:42 AM

Are you sure this will work as you described? I feel like there is a bug somewhere that is preventing a custom taxonomy template. I want to remove the surrounding p tag and just show, the links, so I created the following template:

@using Orchard.Utility.Extensions;
@using Orchard.ContentManagement;

@{
    var terms = (IEnumerable<Contrib.Taxonomies.Models.TermPart>)Model.Terms;
	string name = @Model.ContentField.Name;
}

@if (Model.Terms.Count > 0) {

    @(new HtmlString( string.Join(", ", terms.Select(t => Html.ItemDisplayLink(Html.Encode(t.Name), t.ContentItem ).ToString()).ToArray()) ))
}
<div>TEST</div>

but when I render the template, it still uses the default template you showed above. The shape tracing shows my template, but the outputted html is this:

<p class="taxonomy-field">
    <a href="/categories/coffee-shop">Coffee Shop</a>
</p>

Is there something else i need to do to override the taxonomy template?

Aug 25, 2011 at 7:30 PM

this was user error, turns out there was another template that was created (likely by accident) that was overriding my custom template. I deleted it now it's using the one I want. sorry about that, works great, thanks!