listhtml-lists2sxcsubitem

Is there a way to create a unordered list with subitems from 1 content-type


I would like to create a organogram like: https://codepen.io/bernardoantunes/pen/inrbh using 2sic Content.

I would like to create a content-type 'organogram' with the following fields: Title as String Parent as Entity (of type Organogram) Description as String Link as Hyperlink

Using this content-type i would add some elements where child elements could be created. for example: - Root - Child 1 (Root is selected in the Parent field) - Child 2 (Root is selected in the Parent field) - Child 3 (Child 2 is selected in the Parent field)

Could this be done using 2sic content App?

I created the content-type and added some elements. Created a razor template and then it gives an error. operator '==' can not be applied to operands of type System.Collections.Generic.List and ToSic.SexyContent.DynamicEntity

Razor template:

@using Connect.Koi;
@{
var first = AsDynamic(Data["Default"]).First();
var all = AsDynamic(Data["Default"]);
}
<div>@first.Title</div>  
var children = all.Where(x => x.parent == first).ToList();
<div>@children.Count</div>

Solution

  • Basically the AsDynamic(...) creates wrapped entity-objects, whereas ...parent gives you a list of related items (because it could have more than 1 parent). If this is the code you want to use, I suggest 1 things.

    1. On the .parent (which should probably be .Parent) use the [0] or .FirstOrDefault() so it's .Parent.FirstOrDefault() == first - remember to enable LINQ by @using System.Linq
    2. Don't compare the AsDynamic objects, because they will be different objects. Better compare the id using .EntityId or something.

    So you're resulting compare will probably be .Parent[0].EntityId == first.EntityId.

    What I don't like about your solution is the idea, that the first item in the Default-list will somehow be the important one. This doesn't feel right, but I don't know your whole solution...