Copied to clipboard

Flag this post as spam?

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


  • Yadwinder singh 43 posts 112 karma points
    Jul 18, 2013 @ 09:57
    Yadwinder singh
    0

    Start new div tag after 3 items

    Is there any razor script example (cshtml) how i can do this? 

    Thanks

     

    <div class="row">

    <div class="span4 carshow">

    <img src="images/engines.jpg" alt="Auto Show - Deland, FL" />

    <h2>Deland, FL</h2>

    <h3>October 20, 2009</h3>

    <p>Downtown</p>

    </div>

                    <div class="span4 carshow">

    <img src="images/headlights.jpg" alt="Auto Show - Houston, TX" />

    <h2>Houston, TX</h2>

    <h3>October 12, 2008</h3>

    <p>Everything's </p>

    </div>

                    <div class="span4 carshow">

    <img src="images/hoodornaments.jpg" alt="Auto Show - Carson City, NV" />

    <h2>Carson City, NV</h2>

    <h3>August 14, 2008</h3>

    <p>Enjoy Classic Cars </p>

    </div>

    </div> <!-- row 1 -->

           <div class="row">

    <div class="span4 carshow">

    <img src="images/interiors.jpg" alt="Auto Show - Albuquerque, NM" />

    <h2>Albuquerque, NM</h2>

    <h3>April 2, 2008</h3>

    <p>Don't make a wrong turn.</p>

    </div>

                    <div class="span4 carshow">

    <img src="images/tires.jpg" alt="Auto Show - Oak Park, IL" />

    <h2>Oak Park, IL</h2>

    <h3>December 3, 2007</h3>

    <p>Specializing</p>

    </div>

                    <div class="span4 carshow">

    <img src="images/turnlights.jpg" alt="Auto Show - Clarence, IA" />

    <h2>Clarence, IA</h2>

    <h3>June 20, 2007</h3>

    <p>Come get a </p>

    </div>

    </div><!-- row 2 -->

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 18, 2013 @ 10:06
    Jeavon Leopold
    0

    Hi Yadwinder,

    Can you post the code you are using to loop through your collection? Also are you using a Razor macro (webforms) or a Mvc View/Partial View?

    Thanks,

    Jeavon

  • Yadwinder singh 43 posts 112 karma points
    Jul 18, 2013 @ 10:10
    Yadwinder singh
    0

    Hi Jeavon,

    Thanks for reply.

    I am a beginner.so idon't have much knowledge about razor.

    I use the following code using Razor macro.

    <div class="row">

    @{

    if (Model.HasValue("homepagecontentfolder"))

     {

        var content = Library.NodeById(Model.homepagecontentfolder);

      for(var i=0;i>3;i++)

        {

            <div class="row"></div>

        }

     foreach (var items in @content.Children)

      {

    <div class="span4 carshow">

       <img src='@items.Media("image", "umbracoFile")'   />

              <h2>@items.heading</h2>

     <h3>@items.date</h3>

              <p>@items.summary</p>

           </div>

      }

  • Lars-Erik Aabech 350 posts 1102 karma points MVP 8x c-trib
    Jul 18, 2013 @ 10:27
    Lars-Erik Aabech
    0

    You should use the modulo (%) operator and a counter.

     <div class="row">
    @for(var i = 0; i<yourList.Count; i++)
    {
    <div class="span4 carshow">...</div>
    if (i % 3 == 2) // i / 3 == [product of 3], i % 3 == rest == 2 after each 3 since base is 0
    {
    </div>
    <div class="row">
    }
    }
    </div>
  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 18, 2013 @ 10:32
    Jeavon Leopold
    2

    I would recommend the use of the InGroupsOf collection method, e.g:

     @{
        if (Model.HasValue("homepagecontentfolder"))
        {
            var content = Library.NodeById(Model.homepagecontentfolder).InGroupsOf(3);
            foreach (var group in content)
            {
                <div class="row">
    
                @foreach (var items in group)
                {
                    <div class="span4 carshow">
                        <img src='@items.Media("image", "umbracoFile")'   />
                        <h2>@items.heading</h2>
                        <h3>@items.date</h3>
                        <p>@items.summary</p>
                    </div>
                }
            </div>
            }
        }
    }

     

     

  • Lars-Erik Aabech 350 posts 1102 karma points MVP 8x c-trib
    Jul 18, 2013 @ 10:40
    Lars-Erik Aabech
    1

    @Jaevon - nice extension. :) Didn't know about that one.

    Another tip to @Yadwinder:

    It's generally a better approach to use floating divs and a css "clearfix" rather than nesting divs. (google it)

    Like so:
    <div class="span4 carshow">...</div> (x 3)
    <div class="clearfix"></div>
    <div class="span4 carshow">...</div> (x 3)
    <div class="clearfix"></div>
    ...

    Here's a nice tutorial:
    http://css-tricks.com/all-about-floats/

  • Yadwinder singh 43 posts 112 karma points
    Jul 18, 2013 @ 11:03
    Yadwinder singh
    0

    Hey Jeavon,

    Thanks for reply again.

    but it's not working for me

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 18, 2013 @ 11:05
    Jeavon Leopold
    0

    Ah, I see I missed the Children collection, try:

    var content = Library.NodeById(Model.homepagecontentfolder).Children.InGroupsOf(3);

     

  • Yadwinder singh 43 posts 112 karma points
    Jul 18, 2013 @ 11:11
    Yadwinder singh
    0

    oh! Thanks a lot.

    it works for me.

    please give me any web reference from where i learn Razor and Xslt.

    Thanks again.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 18, 2013 @ 12:17
    Dennis Aaen
    0

    Hi Yadwinder,

    I will try to give some web reference where you can learn XSLT and Razor from.

    Razor:

    http://umbraco.com/help-and-support/video-tutorials/umbraco-fundamentals/razor.aspx ;

    http://umbraco.com/help-and-support/video-tutorials/umbraco-fundamentals/razor-recipes.aspx

    http://our.umbraco.org/documentation/Cheatsheets/DynamicNodeRazor.pdf

    http://our.umbraco.org/documentation/v480/Reference/Templating/Macros/Razor

    XSLT:

    http://pimpmyxslt.com/articles/

    http://pimpmyxslt.com/axesviz.aspx this is a good visual view when you are working with axis in Umbraco

    http://our.umbraco.org/wiki/reference/xslt/xpath-axes-and-their-shortcuts

    http://umbraco.com/help-and-support/video-tutorials/umbraco-fundamentals/xslt-in-umbraco-45.aspx

    http://our.umbraco.org/wiki/reference/xslt/45-xml-schema/xslt-examples-updated-to-new-schema

    I know that the team behind Umbraco, working on a new version of Umbraco.tv, where they will focus on Razor. But for now is in beta http://beta.umbraco.tv.

    I hope these web references can help you learning XSLT and Razor, but if you got any problems, you just have to ask in this forum, and lots of the forums users will love to help you solve the problem you may have.

    /Dennis

  • Yadwinder singh 43 posts 112 karma points
    Jul 18, 2013 @ 12:27
    Yadwinder singh
    0

    Hey jeavon,

    Is there any another method to do this without grouping items.

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 18, 2013 @ 12:30
    Jeavon Leopold
    0

    You could use the method posted by Lars-Erik but why would you not want to group?

  • Yadwinder singh 43 posts 112 karma points
    Jul 18, 2013 @ 14:59
    Yadwinder singh
    0

    Thanks a lot again for reply.

    I find the solution.

    I prefer this one, because i want to sort the items date wise.

    and in grouping items are sorted within groups. 

    <div class="row">

    @{

    if (Model.HasValue("homepagecontentfolder"))

     {

        var content = Library.NodeById(Model.homepagecontentfolder);

        var i=0;

     foreach (var items in @content.Children.OrderBy("date desc"))

      {

     if (i % 3 == 0)

                {

                   @Html.Raw("</div><div class=\"row\">")

                } 

     <div class="span4 carshow">

       <img src='@items.Media("image", "umbracoFile")'   />

              <h2>@items.heading</h2>

              <h3>@items.date.ToLongDateString()</h3>

              <p>@items.summary</p>

            </div>

      i++;

         }

     }

    }

    </div>

  • Lars-Erik Aabech 350 posts 1102 karma points MVP 8x c-trib
    Jul 18, 2013 @ 15:05
    Lars-Erik Aabech
    1

    (Not sure why your reply isn't here yet, but here's an answer to the ordering problem. :) )

    You can chain linq extension methods, so you can order, then group. (And order again if you want)

    var groups = Library.NodeById(Model.homepagecontentfolder).Children.OrderBy("date desc").InGroupsOf(3)
    foreach(var group in groups)
    {
    //...
    foreach(var item in group.OrderBy(".. if you want"))
    {
    }
    }
Please Sign in or register to post replies

Write your reply to:

Draft