Sitecore Glass Mapper Get All Siblings

I am trying to get all the elements at the current element level. For this I use Glass Mapper SitecoreQuery. I can get the current item, but could not match all the siblings

public class TestModel:BaseModel
{
    [SitecoreQuery("../*")]
    public virtual IEnumerable<Model1> Siblings { get; set; }
}

[SitecoreType(AutoMap = true)]
public class Model1 : BaseModel
{

}

The base model has all the necessary fields and is correctly displayed. I'm actually trying to display all the elements at the level of the current element.

+4
source share
1 answer

Add the second parameter to SitecoreQuery: IsRelative = trueas follows:

[SitecoreQuery("../*", IsRelative = true)]
public virtual IEnumerable<Model1> Siblings { get; set; }

It tells Sitecore to start the query at the level of your element, rather than starting at the root of the tree.

Sitecore

0

Source: https://habr.com/ru/post/1657306/


All Articles