Copied to clipboard

Flag this post as spam?

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


  • Darren Wilson 226 posts 594 karma points
    Jul 27, 2017 @ 09:36
    Darren Wilson
    0

    Content Picker URL output in loop

    Morning folks,

    I'm having a bit of an issue trying to get the url of a content picker datatype to output within a loop - the old dynamic version in 7.5 doesn't work anymore in 7.6:

    @{
    var selection = Model.Content.Site().FirstChild("SlideshowRepository").Children<Slide>()
    
                    .Where(x => x.IsVisible());
    }
     <div id="myCarousel" class="carousel slide" data-ride="carousel">
    <div class="carousel-inner">
        @foreach (var item in selection)
        {
            <div class="item @item.IsFirst("active")">
                <div class="fill" style="background: url(@item.BackgroundImage.Url) center bottom / cover no-repeat scroll;"></div>
    
                    <div class="carousel-caption carousel-caption-centre">
                        <div class="row">
                        <div class="col-sm-5">
                        <h2>@Html.Raw(item.GetPropertyValue("Title"))</h2>
                        <p>@item.IntroText</p>
    
                        // THIS IS THE OLD BIT THAT ISN'T WORKING
    
                        @if (item.HasValue("SlideLink"))
                        {
                            <p><a class="btn btn-lg btn-primary" href="@Umbraco.Content(item.SlideLink).Url" role="button">Learn More</a></p>
    
    
                                }
    
                        </div>
    
                        <div class="col-sm-7">
    
                        @if (item.HasValue("Image"))
                        {
                            <img src="@item.Image.Url" class="img-responsive slideshow">
                        }
    
                        </div>
                        </div>
    
                   </div>
    
                </div>
            }
    </div>
    
    <div class="container">
        <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
            <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
            <span class="sr-only">Previous</span>
        </a>
        <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
            <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
            <span class="sr-only">Next</span>
        </a>
    </div>
    

    This is probably a really simple thing to do - but i just can't figure it out.

    Thanks Darren

  • Alex Skrypnyk 6131 posts 23950 karma points MVP 7x admin c-trib
    Jul 27, 2017 @ 14:10
    Alex Skrypnyk
    0

    Hi Darren

    It should work:

    @{
        var selection = Model.Content.Site().FirstChild("SlideshowRepository").Children<Slide>().Where(x => x.IsVisible());
    }
    <div id="myCarousel" class="carousel slide" data-ride="carousel">
        <div class="carousel-inner">
            @foreach (var item in selection)
            {
                <div class="item @item.IsFirst("active")">
                    <div class="fill" style="background: url(@item.BackgroundImage.Url) center bottom / cover no-repeat scroll;"></div>
    
                    <div class="carousel-caption carousel-caption-centre">
                        <div class="row">
                            <div class="col-sm-5">
                                <h2>@Html.Raw(item.Title)</h2>
                                <p>@item.IntroText</p>
    
                                // THIS IS THE OLD BIT THAT ISN'T WORKING
    
                                @if (item.HasValue("SlideLink"))
                                {
                                    <p><a class="btn btn-lg btn-primary" href="@item.SlideLink.Url" role="button">Learn More</a></p>
                                }
    
                            </div>
    
                            <div class="col-sm-7">
    
                                @if (item.HasValue("Image"))
                                {
                                    <img src="@item.Image.Url" class="img-responsive slideshow">
                                }
    
                            </div>
                        </div>
    
                    </div>
    
                </div>
            }
        </div>
    
        <div class="container">
            <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
                <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
                <span class="sr-only">Previous</span>
            </a>
            <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
                <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
                <span class="sr-only">Next</span>
            </a>
        </div>
    </div>
    
  • Alex Skrypnyk 6131 posts 23950 karma points MVP 7x admin c-trib
    Jul 27, 2017 @ 14:10
    Alex Skrypnyk
    0

    What line causes the problem?

  • Darren Wilson 226 posts 594 karma points
    Jul 28, 2017 @ 08:07
    Darren Wilson
    0
                        <p><a class="btn btn-lg btn-primary" href="@Umbraco.Content(item.SlideLink).Url" role="button">Learn More</a></p>
    

    SlideLink is the Content Picker Datatype - this doesn't produce anything. Using @item.Slidelink.Url produces a YSOD saying Slidelink is not defined.

    Cheers Darren

  • Alex Skrypnyk 6131 posts 23950 karma points MVP 7x admin c-trib
    Jul 28, 2017 @ 14:44
    Alex Skrypnyk
    100

    Hi Darren

    What about this code:

    <p><a class="btn btn-lg btn-primary" href="@Umbraco.TypedContent(item.GetPropertyValue<int>("SlideLink")).Url" role="button">Learn More</a></p>
    

    Thanks,

    Alex

  • Darren Wilson 226 posts 594 karma points
    Jul 31, 2017 @ 08:15
    Darren Wilson
    0

    Thanks Alex, I'll give this a go!

  • Darren Wilson 226 posts 594 karma points
    Jul 31, 2017 @ 14:40
    Darren Wilson
    1

    Cheers Alex - works! Marked it as solution...

  • Alex Skrypnyk 6131 posts 23950 karma points MVP 7x admin c-trib
    Jul 31, 2017 @ 14:40
    Alex Skrypnyk
    0

    You are welcome, Darren, glad to help.

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft