Copied to clipboard

Flag this post as spam?

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


  • Peter Schermers 112 posts 134 karma points
    Nov 14, 2012 @ 10:44
    Peter Schermers
    0

    Combining 'pagination' and 'embedded content' in Umbraco

    As the topic reads, I'm trying to combine those two together.

    Here's the scenario:

    1. I have a general productpage in Umbraco, just to keep all products together (no options or code here)
    2. The user can create product categories (nodes) beneath it
    3. *This is NOT what I need pagination for since I was already able to show the list of product categories
    4. Inside these categories (you guessed it) am I using Embedded Content to let the user create unlimited products
    5. So here's my point: I've read the tutorial about how to create pagination inside Umbraco using Razor, but this is meant for NODES. And since I'm using EMBEDDED CONTENT instead, I really have no idea how to edit the provided code to get Umbraco to paginate all the products inside the categories

    What do I do?

    Thanks in advance!

  • Peter Schermers 112 posts 134 karma points
    Nov 14, 2012 @ 10:48
    Peter Schermers
    0

    PS: Of course I would like to have this code in such a way that I can define the parent node ("products", which has ID 1089), and to have the code get all the children of this parent (categories) and to show the embedded content-items (products) inside these.

    Or am I asking too much here? :-)

  • Peter Schermers 112 posts 134 karma points
    Nov 16, 2012 @ 09:52
    Peter Schermers
    0

    Okay, I have been trying to combine the two pieces of code (one for pagination and one for embedded content) myself, and finally got at working. Almost.
    I just have one last line of code I can't get to work, and this essential line makes sure that, instead of ALL items, just the MAX items are shown per page.

    Here's the code I can't get to work because of these lines:

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{
        int pageSize; // How many items per page
        int page; // The page we are viewing

        /* Set up parameters */
       
        if (!int.TryParse(Parameter.PageSize, out pageSize))
        {
            pageSize = 3;
        }

        if (!int.TryParse(Request.QueryString["page"], out page))
        {
            page = 1;
        }

        /* This is your basic query to select the nodes you want */

        var nodes = @Model.producten;
       
        int totalNodes = nodes.Count();
        int totalPages = (int)Math.Ceiling((double)totalNodes / (double)pageSize);
       
        /* Bounds checking */
       
        if (page > totalPages)
        {
            page = totalPages; 
        }
        else if (page < 1)
        {
            page = 1;
        }
    }

    @foreach (var item in nodes.Skip((page - 1) * pageSize).Take(pageSize)) //When I add .Skip or .Take, it stops working
    {
        <div class="span8">
            <div class="prod_foto">
                <img src="@Library.MediaById(@item.prod_foto.InnerText).Url" />
            </div>
            <div class="prod_tekst">
                <h1>@item.prod_naam.InnerText</h1>
                <p>@item.prod_oms.InnerText</p>
            </div>
        </div>
    }
       
    <div class="pagination pagination-centered">
        <ul>
            @for (int p = 1; p < totalPages + 1; p++)
            {
                string active = (p == page) ? "active" : String.Empty;
                <li class="@active"><a href="?page=@p" title="Go to page @p of results">@p</a></li>
            }
        </ul>
    </div>

    As soon as I add 'Skip' or 'Take' to the foreach loop, everything stops working.
    How can I change this to make it working?

    Again, it's just this one line I can't get to work for my website to be finished.
    Any help would be greatly appreciated! ;-)

    Thanks in advance!

  • Tommy Turkijevic 7 posts 28 karma points
    Nov 16, 2012 @ 11:13
    Tommy Turkijevic
    1

    So when you use Skip or Take it do not work ?

    I will sit down and create a structure like yours and try to do this aswell, is the products children of a node or is it in its own root level ?

    What umbraco version are you using ?

    /Tommy

  • Peter Schermers 112 posts 134 karma points
    Nov 16, 2012 @ 11:16
    Peter Schermers
    0

    Hi Tommy,

    I posted my question at the Embedded Content project as well and got an answer back.
    To be honest, I don't really know how to combine his advice with my code, but I'm guess I have to go and find out.

    Here's the link:

    http://our.umbraco.org/projects/backoffice-extensions/embedded-content/bugs/36202-Embedded-Content-doesn't-work-with-Skip()-or-Take()?p=0#comment131168

    Thanks for your help!

  • Peter Schermers 112 posts 134 karma points
    Nov 16, 2012 @ 11:59
    Peter Schermers
    0

    Got it working without .Skip or .Take with the help of a professional Umbraco developer.

    Thanks anyway, Tommy! ;-)

  • Tommy Turkijevic 7 posts 28 karma points
    Nov 16, 2012 @ 13:06
    Tommy Turkijevic
    0

    Super ! How did you solve it ?

     

    /Tommy

Please Sign in or register to post replies

Write your reply to:

Draft