Deb
Deb

Reputation: 401

Sitecore Glass Mapper Get All Siblings

I am trying to get all items at the current item level. I am using Glass Mapper SitecoreQuery for the same. I am able to get the current item but not able to map all siblings

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

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

}

Base Model has all the required fields and correctly mapped. I am actually trying to display all items at the level of current item.

Upvotes: 4

Views: 793

Answers (1)

Marek Musielak
Marek Musielak

Reputation: 27132

Add second parameter to SitecoreQuery : IsRelative = true like that:

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

It tells Sitecore to start query at your item level instead of starting at the tree root.

You can find more information in the Official Sitecore Glass Mapper Tutorial

Upvotes: 0

Related Questions