Copied to clipboard

Flag this post as spam?

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


  • Henrik Vincent 122 posts 616 karma points
    Oct 09, 2016 @ 12:53
    Henrik Vincent
    0

    Cant get nice url in Partial View Macroo

    Hi

    I'm trying to create a testimonial slider for a business site.

    I've created a repository in the root of the site where testimonials can be created in, so they can be shown from any page of the site

    enter image description here

    Above you see the structure of the site

    My code is as follows:

        @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        var testimonialSection = Umbraco.TypedContentAtRoot().FirstOrDefault(x => x.DocumentTypeAlias == "testimonials");
    }
    
    @if (testimonialSection != null)
    {
        <ul id="clientTestimonials">
            @foreach (var item in testimonialSection.Children)
            {
                var client = Umbraco.TypedMedia(item.GetPropertyValue("clientLogo"));
    
                if (client != null)
                {
    <li class="testimonialWrap">
                <div class="testimonialHead">   
                    <img src="@client.Url" alt='@item.GetPropertyValue("clientLogoAlt")'/> 
                </div>
                    <div class="testimonialBody">
                        <strong>@item.GetPropertyValue("clientName") <br> @item.GetPropertyValue("clientCompany"):</strong>
                        <div class="clientTestimonial">
                            <p>@item.GetPropertyValue("clientTestimonial")</p>
                        </div>
                            <p>@item.GetPropertyValue("clientEnding")</p>
                    </div>
                    <a href='@item.GetPropertyValue("clientCaseLink")' class="testimonialBtn">
                    <span id="testimonialArrow"><i class="fa fa-arrow-right" aria-hidden="true"></i></span>
                </a>
            </li>
                }
            }
        </ul>
    }
    

    I'm picking the destination links (clientCaseLink) in a content picker, and the llink works, but it's the ID and not the nice URL being shown.

    I've tried a ton of stuff, but can seem to make it work.

    I guess it's some small thing that I just can't seem to figure out, so hope you guys can help me

    Best Henrik

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Oct 09, 2016 @ 14:14
    Dennis Aaen
    100

    Hi Henrik,

    Have you seen the documentation for the content picker. Here you will find Razor examples on how to get the data out. There are examples on dynamic and strongly typed Razor.

    https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/content-picker

    For your example could you please try to use the code below. Something like this should work for you

      @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        var testimonialSection = Umbraco.TypedContentAtRoot().FirstOrDefault(x => x.DocumentTypeAlias == "testimonials");
    }
    
    @if (testimonialSection != null)
    {
        <ul id="clientTestimonials">
            @foreach (var item in testimonialSection.Children)
            {
                var client = Umbraco.TypedMedia(item.GetPropertyValue("clientLogo"));
    
                if (client != null)
                {
    <li class="testimonialWrap">
                <div class="testimonialHead">   
                    <img src="@client.Url" alt='@item.GetPropertyValue("clientLogoAlt")'/> 
                </div>
                    <div class="testimonialBody">
                        <strong>@item.GetPropertyValue("clientName") <br> @item.GetPropertyValue("clientCompany"):</strong>
                        <div class="clientTestimonial">
                            <p>@item.GetPropertyValue("clientTestimonial")</p>
                        </div>
                            <p>@item.GetPropertyValue("clientEnding")</p>
                    </div>
                    @{ 
                        var node = Umbraco.TypedContent(item.GetPropertyValue<int>("clientCaseLink"));
                        <a href='@node.Url' class="testimonialBtn">
                           <span id="testimonialArrow"><i class="fa fa-arrow-right" aria-hidden="true"></i></span>
                       </a>
                    }
    
            </li>
                }
            }
        </ul>
    }
    

    Hope this helps, and can get your further.

    /Dennis

  • Henrik Vincent 122 posts 616 karma points
    Oct 09, 2016 @ 14:51
    Henrik Vincent
    0

    Hi Dennis

    Thank you very much for your help.

    I'm still kinda new to Razor, so I see that, what I've done wrong, was not adding the var in the @{} together with the link, but instead I placed it with the other var for the image.

    Now it made sense :)

    Again. Thanks alot!

    Henrik

Please Sign in or register to post replies

Write your reply to:

Draft