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
    Jul 27, 2016 @ 15:01
    Henrik Vincent
    0

    Creating a frontpage testimonialslider with repository

    Hi guys

    Not sure whether the title is descriptive enough but here goes.

    I'm working on a company site and on the front page, I'm creating a modal that reveals a slider with customer testimonials.

    What I want to do, is make a repository in the root in which it is possible to create new testimonials with: client logo clientname testimonial link to client case

    I did this years ago in umbraco 4, but haven't worked with it since. I lost my old book from my lvl 1 class, but I'm guessing that's rather obsolete anyways.

    I tried Googling for hours, but not sure if I'm even searching for the right thing.

    Hope you guys can send me in the right direction, cus I feel rather lost here.

    Hope you can helkp me out Kind regards Henrik

  • Fergus Davidson 309 posts 588 karma points
    Jul 27, 2016 @ 15:36
    Fergus Davidson
    1

    i am sure there are many way to accomplish this, but in a package-free way, i think something like:

    • create a 'testimonials folder' doctype create a 'testimonial' doctype

    • create the testimonial folder in a shared content node outside the site, so they do not appear in the site structure, or hidden somewhere in the site.

    • add the testimonials to this node

    • on your homepage doctype, add a MNTP property with its root selction point as the testimonials folder node

    • on the homepage template, add a partial view to list the contents of the MNTP

  • Henrik Vincent 122 posts 616 karma points
    Jul 28, 2016 @ 12:09
    Henrik Vincent
    0

    Thank salot for the suggestion. I've created the doctypes and set it all up. and it renders each item in the MNTP, but my problem is, that it doesn't fetch the data from my testimonial items. My structure is

    Root
    -Frontpage
    --other stuff
    --other stuff
    -Testimonials
    --Testimonial1
    --Testimonial2
    --Testimonial3

    MNTP is located on Frontpage with testimonials as property

    The view is as follows:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{ var selection = CurrentPage.testimonials.Split(','); }
    
    <ul id="clientTestimonials">
        @foreach (var id in selection)
        {
            var item = Umbraco.Content(id);
            <li class="testimonialWrap">
    
                <div class="testimonialHead">
                     @if (CurrentPage.HasValue("clientLogo")){ 
                    var dynamicMediaItem = Umbraco.Media(CurrentPage.clientLogo); 
                <img src="@dynamicMediaItem.umbracoFile" alt='@Umbraco.Field("imageAlt")'/> 
    }           
                </div>
                    <div class="testimonialBody">
                    @Umbraco.Field("clientInfo")
                        </div>
                <div class="testimonialBtn">
                    @Umbraco.Field("clientTestimonial")
                </div>
                    <a href="@item.Url">@item.Name</a>
            </li>
        }
    </ul>
    

    Could the problem be because both testimonials and frontpage are located in root?
    Or am I missing something?

    Edit:
    I'm prestty sure my problem is, that there's no connection between my MNTP and my Testimonials folder. At least not datawise.
    Reason for this is, when I pick items from testimonials folder via the MNTP, they are displayed on the page, but no data from the input fields.
    How do you link these together?
    Thanks in advance
    Henrik

  • Ian 178 posts 752 karma points
    Jul 29, 2016 @ 15:57
    Ian
    100

    When you are doing this

    var item = Umbraco.Content(id);
    

    you are retrieving a dynamic representation of IPublishedContent the model that sits behind the testimonial (and all published pages in umbraco)

    CurrentPage however is the dynamic representation of the page currently being viewed in the browser

    Umbraco.Field(.. gets the value of a field existing on the current page in the browser only.

    This mean this bit is correct

    @{ var selection = CurrentPage.testimonials.Split(','); }
    

    This bit isn't

    @Umbraco.Field("clientInfo")
    

    Instead this ...

    @item.clientInfo
    

    would display the value of the clientInfo field when it exists on the testimonial

  • Henrik Vincent 122 posts 616 karma points
    Jul 29, 2016 @ 20:17
    Henrik Vincent
    0

    Thank you SO much Ian!!!!
    That was a very big help.

    On a sidenote. Is there an equivalent to @item. for media, cus I'm not 100% sure how to insert the images since CurrentPage is used in the code I've been using other places on the site.. I've tried several different methods but most end out in Yellow screen of death

     @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
        @{ var selection = CurrentPage.testimonials.Split(','); }
    
        <ul id="clientTestimonials">
            @foreach (var id in selection)
            {
                var item = Umbraco.Content(id);
                <li class="testimonialWrap">
                    <div class="testimonialHead">
    
                        </div>
                        <div class="testimonialBody">
                         @if (CurrentPage.HasValue("clientLogo")){ 
                        var dynamicMediaItem = Umbraco.Media(CurrentPage.clientLogo); 
                    <img src="@item.clientlogo.umbracoFile" alt='@Umbraco.Field("imageAlt")'/> 
        }      
                            <strong>@item.clientInfo</strong>
                            <p>@item.clientTestimonial</p>
                            <p>@item.clientEnding</p>
                        </div>
                    <a href="@item.clientCaseLink" class="testimonialBtn">
                        <span id="testimonialArrow"><i class="fa fa-arrow-right" aria-hidden="true"></i></span>
                    </a>
                </li>
            }
        </ul>
    
  • Ian 178 posts 752 karma points
    Jul 29, 2016 @ 22:09
    Ian
    1

    Again some of what are doing is correct and some isnt. In my first post i mentioned abot currrntpage i idwntified the line that was correct. With the code you have there should be no further use of currentpage.

    Now you need to go back through the code to thinking where does the information originate from that i want to display?

    Does the current page in the browser have a client logo property no.

    Its the testimonial that has the logo.

    Im looping through several testimonials but at the point where my code retrieves the logo image im inside the loop and ive set variable for this testimonial to 'item'.

    Therefore any operation you want to perform should be using item. item.hasvalue ... item.clientLogo etc.

    Other than that umbraco.media for retrieving images is correct. It is the equivalent of umbraco.content for pages but is only used for media items.

  • Henrik Vincent 122 posts 616 karma points
    Jul 31, 2016 @ 10:11
    Henrik Vincent
    1

    Once again thank you very much Ian

    I finally got it working

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{ var selection = CurrentPage.testimonials.Split(','); }
    
    <ul id="clientTestimonials">
        @foreach (var id in selection)
        {
            var item = Umbraco.Content(id);
            var dynamicMediaItem = Umbraco.Media(@item.clientLogo); 
            <li class="testimonialWrap">
                <div class="testimonialHead">   
                    <img src="@dynamicMediaItem.umbracoFile" alt='@Umbraco.Field("imageAlt")'/> 
                </div>
                    <div class="testimonialBody">
                        <strong>@item.clientInfo</strong>
                        <div class="clientTestimonial">
                            @item.clientTestimonial
                        </div>
                            @item.clientEnding
                    </div>
                <a href="@item.clientCaseLink" class="testimonialBtn">
                    <span id="testimonialArrow"><i class="fa fa-arrow-right" aria-hidden="true"></i></span>
                </a>
            </li>
        }
    </ul>
    
  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Jul 31, 2016 @ 12:46
    Alex Skrypnyk
    0

    Hi Henrik,

    Just for information strongly typed variant, but without using ModelBuilder:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    
    @{ var selection = Umbraco.AssignedContentItem.GetPropertyValue<string>("testimonials").Split(','); }
    
    <ul id="clientTestimonials">
        @foreach (var id in selection)
        {
            var item = Umbraco.TypedContent(id);
            var mediaItem = Umbraco.TypedMedia(item.GetPropertyValue("clientLogo"));
            <li class="testimonialWrap">
                <div class="testimonialHead">
                    <img src="@mediaItem.Url" alt='@mediaItem.GetPropertyValue("imageAlt")' />
                </div>
                <div class="testimonialBody">
                    <strong>@item.GetPropertyValue("clientInfo")</strong>
                    <div class="clientTestimonial">
                        @item.GetPropertyValue("clientTestimonial")
                    </div>
                    @item.GetPropertyValue("clientEnding")
                </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>
    

    Best,

    Oleksandr

Please Sign in or register to post replies

Write your reply to:

Draft