Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Kieron 132 posts 338 karma points
    Sep 12, 2018 @ 16:54

    If X Matches Current Page ID, OR Any of Current Page's Descendants - is it possible?

    Hi guys, got this snippet ive put together:

    @foreach(var item in selection){
        if(item.HasValue("location") && @Model.Content.Id == @item.GetPropertyValue<int>("location")){
    var singleLink = item.GetPropertyValue<Link>("links");
        if(singleLink != null)
                IPublishedContent mediaItem = item.GetPropertyValue<IPublishedContent>("wideImage");
                   <div class="owl-item" style="width: 891px;"><a href="@singleLink.Url" target="@singleLink.Target"><img class="tag-headadvert img-responsive" style="display: inline;" src="@mediaItem.Url" width="100%" alt="@singleLink.Name" /></a></div> 

    In the second line you can see I make a comparison of the current page ID, vs a variable, is there a way to do, if that variable matches the current page ID, or any descendants of the current page ID?


  • Claushingebjerg 805 posts 2044 karma points
    Sep 14, 2018 @ 10:05

    Something like this maybe:

    var active = Model.Content.AncestorsOrSelf().Select(x => x.Id).ToArray().Contains(1020);
Please Sign in or register to post replies

Write your reply to: