Copied to clipboard

Flag this post as spam?

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


  • Paul Griffiths 370 posts 1021 karma points
    Jun 28, 2016 @ 08:12
    Paul Griffiths
    0

    isHelpers 'Help'

    Hi All,

    I have the following code

    @{
        //gets the home page using doc type alias (root node)
        var siteRoot = Model.Content.AncestorOrSelf("homePage");
        //gets the products page using doc type alias
        var galleryPage = siteRoot.Descendant("galleryPage");
        //get the latest photos using the album media folder id
        var latestPhotos = galleryPage.HasValue("album") ? Umbraco.TypedMedia(galleryPage.GetPropertyValue<int>("album")) : null;
    }
    
            @if (latestPhotos != null)
            {
                foreach (var photo in latestPhotos.Children.OrderBy("createDate desc"))
                {
                    <div class="item @(photo.IsPosition(1, "col-xs-6", "col-md-2 col-sm-3 col-xs-4"))">
                        <a href="@photo.Url" data-gallery><img class="img-responsive" src="@photo.GetCropUrl(320,320)" alt="" /></a>
                    </div>
                }
            }
    

    I am trying to use the isHelpers to test whether 'photo' is in the first two positions in my 'latestPhotos' list. Is that possible? My code above can successfully check if the photo is in position 1 then apply x class and if not apply y class.

    Is there a way to check against more than one position? I been reading this on the wiki

    https://our.umbraco.org/documentation/reference/querying/ipublishedcontent/ishelpers

    Thanks

    Paul

  • Nik 1625 posts 7295 karma points MVP 7x c-trib
    Jun 28, 2016 @ 08:21
    Nik
    0

    Hi Paul,

    What about if you nested the checks. It's not something I've done before but this might do the job.

    @(photo.IsFirst("col-xs-6", photo.IsPosition(2, "col-xs-6", "col-md-2 col-sm-3 col-xs-4"))
    

    Nik

  • Paul Griffiths 370 posts 1021 karma points
    Jun 28, 2016 @ 08:54
    Paul Griffiths
    0

    Hi Nik,

    Thansk for the response - I will take a look at whether this works. I was just looking for a better way of achieving the following and was wondering if the isHelpers could help

    @if (latestPhotos != null) { var indexCount = 0;

                    foreach (var photo in latestPhotos.Children.OrderBy("createDate desc"))
                    {
                        if (indexCount == 0 || indexCount == 1)
                        {
                            <div class="item col-xs-6">
                                <a href="@photo.Url" data-gallery><img class="img-responsive" src="@photo.GetCropUrl(640,480)" alt="" /></a>
                            </div>
                        }
                        else
                        {
                            <div class="item col-md-2 col-sm-3 col-xs-4">
                                <a href="@photo.Url" data-gallery><img class="img-responsive" src="@photo.GetCropUrl(320,320)" alt="" /></a>
                            </div>
                        }
    
                        indexCount++;
                    }
                }
    

    Many thanks

    Paul

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies