Combining 'pagination' and 'embedded content' in Umbraco
As the topic reads, I'm trying to combine those two together.
Here's the scenario:
I have a general productpage in Umbraco, just to keep all products together (no options or code here)
The user can create product categories (nodes) beneath it
*This is NOT what I need pagination for since I was already able to show the list of product categories
Inside these categories (you guessed it) am I using Embedded Content to let the user create unlimited products
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
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.
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! ;-)
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.
Combining 'pagination' and 'embedded content' in Umbraco
As the topic reads, I'm trying to combine those two together.
Here's the scenario:
What do I do?
Thanks in advance!
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? :-)
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:
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!
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
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!
Got it working without .Skip or .Take with the help of a professional Umbraco developer.
Thanks anyway, Tommy! ;-)
Super ! How did you solve it ?
/Tommy
is working on a reply...