Copied to clipboard

Flag this post as spam?

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


  • EKohl 6 posts 86 karma points
    May 27, 2019 @ 21:27
    EKohl
    0

    How to make Multi-Url Picker work in Nested Content

    I'm having an issue where I have nested content that contains a multi-node picker that is has a maximum number of items is set to 1.

    I'm trying the following, but the link won't show because I think it returns a null even when I have published links in the content.

        <!-- Features -->
        @{
            var features = Model.Value<IEnumerable<IPublishedElement>>("productFeatureList");
            <section class="container mb-3 mt-3">
                <div class="row pb-4">
                    @foreach (var feature in features)
                    {
                    <div class="col-lg-4 col-sm-6 mb-30 pb-4">
                        <div class="card">
                            <div class="card-body">
                                <h4 class="card-title">@feature.GetProperty("featureBenefit").Value()</h4>
                                <p class="card-text">@feature.GetProperty("featureDescription").Value()</p>
                                @{ var moreLink = feature.Value<IPublishedContent>("featureMoreLink");}
                                @if (moreLink != null)
                                {
                                <a href="@moreLink.Url" class="btn btn-gradient mt-2">@moreLink.Name</a>
                                }
                            </div>
                        </div>
                    </div>
                    }
                </div>
            </section>
        }
    
  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    May 29, 2019 @ 15:50
    Søren Gregersen
    0

    Hi,

    Have you tried to get the raw value to see what is stored in "featureMoreLink"?

    Just use feautre.Value("featureMoreLink"), maybe like this:

    @if (moreLink != null) {
        <a href="@moreLink.Url" class="btn btn-gradient mt-2">@moreLink.Name</a>
    } else {
        <text>@feautre.Value("featureMoreLink")</text>
    }
    
  • EKohl 6 posts 86 karma points
    May 29, 2019 @ 16:50
    EKohl
    0

    Thanks for the suggestion. I tried it out with the code below and it definitely displays the results of the "else" part of the statement as: Umbraco.Web.Models.Link

    I'm not sure what do next.

    @{ var moreLink = feature.Value<IPublishedContent>("featureMoreLink");}
    @if (moreLink != null)
    {
    <a href="@moreLink.Url" class="btn btn-gradient mt-2"><i class="[email protected]("fontIcon").Value()"></i> @moreLink.Name</a>
    }
    else
    {
    @feature.Value("featureMoreLink")
    }
    
  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    May 29, 2019 @ 17:17
    Søren Gregersen
    101

    This makes sense :)

    I can't say why your multi-node picker stores a Link (sure it's not a multiurlpicker?), but if you change the type, it should work:

    @{
      var moreLink = feature.Value<Umbraco.Web.Models.Link>("featureMoreLink");}
      var fontIcon = feature.Value<string>("fontIcon");
      if (moreLink != null) {
        <a href="@moreLink.Url" class="btn btn-gradient mt-2"><i class="fe-icon-@fontIcon"></i> @moreLink.Name</a>
      }
    }
    
  • EKohl 6 posts 86 karma points
    May 29, 2019 @ 19:39
    EKohl
    1

    It is a Multi Url Picker. Your help did the trick. I'm still learning how to change the type on things, so I needed an example like that.

    Here's the final code that worked:

    <!-- Features -->
            @{
                var features = Model.Value<IEnumerable<IPublishedElement>>("productFeatureList");
                <div class="row pb-2 pt-4">
                    @foreach (var feature in features)
                    {
                        <div class="col-lg-4 col-sm-6 mb-30 pb-4 d-flex align-items-stretch">
                            <div class="card">
                                <div class="card-body">
                                    <h4 class="card-title">@feature.GetProperty("featureBenefit").Value()</h4>
                                    <p class="card-text">@feature.GetProperty("featureDescription").Value()</p>
                                    @{ var moreLink = feature.Value<Umbraco.Web.Models.Link>("featureMoreLink"); }
                                    @if (moreLink != null) {
                                    <a href="@moreLink.Url" class="btn btn-gradient mt-2"><i class="[email protected]("fontIcon").Value()"></i> @moreLink.Name</a>
                                    }
                                </div>
                            </div>
                        </div>
                    }
                </div>
            }
    
  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    May 29, 2019 @ 19:53
    Søren Gregersen
    0

    We are all still learning ;-)

    Happy I was able to help

Please Sign in or register to post replies

Write your reply to:

Draft