Copied to clipboard

Flag this post as spam?

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


  • Paul Stewart 50 posts 71 karma points
    May 08, 2012 @ 14:26
    Paul Stewart
    0

    Several Lists combined to one in razor

    Hey everyone, Im really struggling with razor. I managed to display my items in the model (using the embedded content tool by theFARM). but on the main testimonials page I wont to combine all lists into one. 

    Embed Content Tool (Testimonials)
    testimonial (multiple textbox)
    customer (textstring)
    alsoshow (content picker, this is for my other testimonials plugin)

    Structure

    Testmonials.aspx (parent)
    - Department1.aspx (child w/ embed content)
    - Department2.aspx (child w/ embed content) 
    - Department3.aspx (child w/ embed content)

    All the child pages work perfectly showing the items, but I want to combine them all on the main landing page so its like on the website you land on the testimonials page you see them all but once you click on the department you only see those testimonials.

    Heres my working code 

    @using umbraco.MacroEngines;
    @{
         
            var itemsList = Model.customerTestimonials;  
                <ul>
                  @foreach (var item in itemsList)
                  {     
                    var customerItem = item.customer.InnerText;
                    var testimonItem = item.testimonial.InnerText;
                   
                    <li>
                       <p>@testimonItem</p>
                       <p class="quoter">@customerItem</p>
                    </li>
                  }
                </ul>
                
    }

    Thats my working version for showing just the department testimonials, but I now need to create one that would show all the departments in random order, I've tried using decendants, children methods but it keeps coming up with DynamicNode containing the values dont exist and am really stuck :( 

  • gilad 185 posts 425 karma points
    May 08, 2012 @ 14:33
    gilad
    0

    Hi paul.

    in testimonials you can make foreeach loop on children and then use same code..

    try this : 

     

    @usingumbraco.MacroEngines;
    @{
          @foreach(var testamonial in Model.Children)
    {
            var itemsList =testamonial.customerTestimonials;  
                <ul>
                  @foreach(varitem initemsList)
                  {    
                    varcustomerItem =item.customer.InnerText;
                    vartestimonItem =item.testimonial.InnerText;
                   
                    <li>
                       <p>@testimonItem</p>
                       <p class="quoter">@customerItem</p>
                    </li>
                  }
                </ul>
    }

     

  • Paul Stewart 50 posts 71 karma points
    May 08, 2012 @ 14:51
    Paul Stewart
    0

    Thank Gilad! but i am getting this error through umbraco.

    Error occured

    Unexpected "foreach" keyword after "@" character. Once inside code, you do not need to prefix constructs like "foreach" with "@". 

  • gilad 185 posts 425 karma points
    May 08, 2012 @ 14:54
    gilad
    0

    remove  the first @ before the first foreach.

    that acourd becuse you open code block with @{

    and then if there is no open HTML TAG like in your second loop ( <ul> ) you dont need to put @ before the foreach.

    Cheers. 

    @{
         foreach(var testamonial inModel.Children)
     
    {
    ....... 
  • Paul Stewart 50 posts 71 karma points
    May 08, 2012 @ 14:59
    Paul Stewart
    0

    Thanks very much Gilad.. you are a life saver! I dont suppose you know how to use the content picker tool to display certain items? for example, I want to show this particular testimonial on page X?  

  • gilad 185 posts 425 karma points
    May 08, 2012 @ 15:06
    gilad
    0

    if you want to do it via content picker  (from page X - with content picker property)

    you can do something like this : 

    add : @inherits umbraco.MacroEngines.DynamicNodeContext to the top of the macro.

    then : 

    dynamic  testamonialsNode  = new DynamicNode(Model."contentPickerPropertyAlias");

    then same loop - 

    @{
         foreach(var testamonial in testamonialsNode.Children)
     
    {
     
    .......

    Hope that help

  • Paul Stewart 50 posts 71 karma points
    May 08, 2012 @ 15:33
    Paul Stewart
    0

    Sorry Gilad, i dont think I explained myself what i meant, lol.. am no sure if I understand the response correctly or what am sorry, just been a hetic day in the office. lol

    for each testimonial created by the embedded content, it has a content picker value which I want the testimonial to show also on so it shows related information, instead of having to rewrite the testimonials on the departments pages and any other page.

    Testimonials
    -department 1 (with embedded contnet)
    -department 2 (with embedded content)
    Deparments
    - Lesuire
    - business
    - deparment example 3 

  • Paul Stewart 50 posts 71 karma points
    May 08, 2012 @ 15:42
    Paul Stewart
    0

    See if i want to randomise the sort the order? how would I achieve that? 

  • gilad 185 posts 425 karma points
    May 08, 2012 @ 15:47
    gilad
    0

    Hii paul,

    i am not sure that i am understand exactly what you are trying to do...

    if you want to disply the same list like in Testimonials page you should get the Testimonials  node for getting  hes childrens.

    Like you use : 

    @{
         foreach(var testamonial in Model.Children)

    So you need to get the node for use :

    @{
         foreach(var testamonial in testamonialsNode.Children)

    for example you can use the id of this node :

     

    dynamic testamonialsNode  = new DynamicNode(1234); // your testamonials id

     

  • Paul Stewart 50 posts 71 karma points
    May 08, 2012 @ 15:58
    Paul Stewart
    0

    Hey Gilad, Ive not got the both Lists now working, for the main testimonials page (one you provided to work) and the short list of the testimonials (original working). What am trying to do now is like I have a option when adding a new testimonial, if I want this testimonial to be displayed on another page throughout the rest of the website. 

Please Sign in or register to post replies

Write your reply to:

Draft