Orchard Taxonomy Terms get direct children in view

526 Views Asked by At

I have a Taxonomy called Categories. In this taxonomy I have multiple levels of terms. Each term is a CategoriesTerm contenttype.

I have defined a custom razor template: Content-CategoriesTerm.cshtml, which is used when I click a CategoriesTerm on the frontend.

Now I want to display on that page all direct children (if any), but there is no property like Term.Children or something. How can I get the children of a term in the Razor view?

1

There are 1 best solutions below

8
On BEST ANSWER

Check Taxonomy.cshtml and Orchard.Mvc.DisplayChildren. It goes like this:

 var tag = Tag(Model, "ul");
    IList<dynamic> items = Model.Items;

    if (items.Any()) {
        items[0].Classes.Add("first");
        items[items.Count - 1].Classes.Add("last");

<div>
    @tag.StartElement
        @* see MenuItem shape template *@
        @DisplayChildren(Model)
    @tag.EndElement
</div>

@DisplayChildren could be done in Razor if you like:

 public IHtmlString DisplayChildren(dynamic shape) {
        var writer = new HtmlStringWriter();
        foreach (var item in shape) {
            writer.Write(Display(item));
        }
        return writer;
    }