Copied to clipboard

Flag this post as spam?

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


  • Sharmarke Hujale 103 posts 346 karma points
    Jun 10, 2016 @ 16:37
    Sharmarke Hujale
    0

    Need help to create a testimonial feature!

    Hey Guys,

    I want to create a testimonial feature on my website to show my clients review about my service

    I want the testimonials to be shown on the home page

    I have created a document type called "testimonals" with some properties and I've created a partial view macro called "Testimonial"

    This is where I've put it (Home.cshtml):

    enter image description here

    And this is my macro fil (Testimonial.cshtml):

    enter image description here

    The code that I have used doesn't work - can someone help me to display the testimonials items on the home.cshtml?

    Best regards,

    Sharmarke

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jun 10, 2016 @ 16:40
    Alex Skrypnyk
    0

    Hi Sharmarke,

    1) First of all, this line doesn't make sense :

    enter image description here

    If you on Home page - user just CurrentPage, you don't need to go through content tree to find home page.

    2) In foreach you can use just

    var item in CurrentPage.Children
    

    Do you have some errors on the page? Or just empty result?

    What about content tree in Umbraco, can you show ?

    Cheers,

    Oleksandr Skrypnyk

  • Sharmarke Hujale 103 posts 346 karma points
    Jun 10, 2016 @ 16:50
    Sharmarke Hujale
    0

    Hi Alex,

    I didn't know that - I just took it from a former project. I do not get any kind of errors - only empty results

    Here's my content tree:

    enter image description here

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jun 10, 2016 @ 16:51
    Alex Skrypnyk
    0

    Did you create macro in Umbraco backoffice? Because you need to create macro before rendering it in razor?

  • Sharmarke Hujale 103 posts 346 karma points
    Jun 10, 2016 @ 16:53
    Sharmarke Hujale
    0

    Yes, I did create a marco

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jun 10, 2016 @ 17:09
    Alex Skrypnyk
    0

    Also add please a checker for children nodes, we need to iterate only in Testimonials pages, so we need something like

    CurrentPage.Children.Children.Where("DocumentTypeAlias == \"Testimonials\"")
    
  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jun 10, 2016 @ 17:14
    Alex Skrypnyk
    0

    I think that problem is with nodes without testimonials properties, so when foreach loops through these nodes, it can be crashed.

  • Sharmarke Hujale 103 posts 346 karma points
    Jun 10, 2016 @ 17:32
    Sharmarke Hujale
    0

    Where should I put that line of code at?

    Is it replaced with this:

    var selection = CurrentPage.AncestorOrSelf(1).Descendants("Home").FirstOrDefault();
    
  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jun 10, 2016 @ 21:31
    Alex Skrypnyk
    100

    Hi Sharmarke,

    No, replace in foreach:

    foreach (var item in CurrentPage.Children.Children.Where("DocumentTypeAlias == \"Testimonials\"")) 
    

    Thanks,

    Alex

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jun 10, 2016 @ 21:43
    Alex Skrypnyk
    0

    Sharmarke, it would be great to paste code like text, not like image )) it's in your interests.

  • Sharmarke Hujale 103 posts 346 karma points
    Jun 12, 2016 @ 22:49
    Sharmarke Hujale
    0

    Hi Alex,

    Sorry for the late reply I was kinda busy. I couldn't paste my code, that's why I send images instead. When write anything after this "<" it deletes everything, which is kinda weird.

    But anyway, thanks to you, your code put me in the right direction and it solved my problem

    var item in CurrentPage.Children.Where("DocumentTypeAlias == \"testimonials\"")
    

    I only changed two things - the first being that my DocumentTypeAlias had a lowercase "t" - and the second being that you wrote "children.children" two times.

    Thanks mate,

    Sharmarke

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jun 13, 2016 @ 15:24
    Alex Skrypnyk
    0

    You are welcome !!!

    Cheers

Please Sign in or register to post replies

Write your reply to:

Draft