Pagination via page template in Plone - pagination

I'm looking for a example on how to use the Batch TAL macro for pagination of folder contents. Up to know didn't find any that explains what to do. Does anyone know of such an example?
Thanks in advance.
Regards,
Helio

Something like that ?
<div tal:define="liste python:here.portal_catalog.searchResults({'portal_type' : 'News Item', 'review_state':'published'});
Batch python:modules['Products.CMFPlone'].Batch;
b_size python:20;
b_start python:0;
b_start request/b_start | b_start;
batch python:Batch(liste, b_size, int(b_start), orphan=1);"
tal:condition="liste">
<ul>
<tal:boucle tal:repeat="item batch">
<li tal:define="oddrow repeat/item/odd;"
tal:attributes="class python:test(oddrow, 'even', 'odd')">
<!-- stuff -->
</li>
</tal:boucle>
</ul>
<div metal:use-macro="here/batch_macros/macros/navigation" />
</div>

Found this resource:
http://raw.zniper.net/bits/batching-in-custom-template
it worked very well.
Regards,
Helio

Related

use href tag for different html pages but with same url id in express

i'm trying to switch between home and profile page for same user with click on each button. also except change between home and profile,id should stay the same.
but after click on profile button only id will be changed and it uses profile as id
(i used ejs as format for my views/html pages)
any idea how can i fix it?is that even possible?
there is my nav code:
<nav>
<div class="nav-wrapper teal darken-4">
BAZAART
<ul class="right hide-on-med-and-down">
<li><a class="waves-effect waves-light btn teal lighten-1" href="home"> <i class="material-icons right">home</i> home</a></li>
<li><a class="waves-effect waves-light btn teal lighten-1" href="profile">profile <i class="material-icons right">account_box</i></a></li>
</ul>
</div>
</nav>
homeController:
exports.sendReqParam = (req, res) => {
let userHome = req.params.userHome;
res.render("home", { name: userHome });
// res.send(`This is the homepage for ${userHome}`);
};
exports.respondWithName = (req, res) => {
let paramsName = req.params.myName;
res.render("profile", { name: paramsName });
}
main.js
app.get("/profile/:myName", homeController.respondWithName);
app.get("/", homeController.respondInfo);
app.get("/home/:userHome", homeController.sendReqParam)
I was recently making a blog website, where I write a post and it displays it on the home page. But if we wanted to go to the specific post page, instead of making another separate page for each new post, we made a post.ejs page instead, and later to acces the specific post we simply used something called lodash. I'll show you an example of it, so it makes more sense, and I'll show you the code we used.
So the example is this, I go to the compose.ejs page and I write a random post: title=Post, content=A random lorem ipsum
and lets say we write another post: title=Another post, content=Another random lorem ipsum
Okay so now everytime we write a blog post it sends us to the home page (where we currently are) and it shows the two blogs posts. If we wanted to go to the specific url of the post, we simply write this link localhost:3000/posts/Another post hit enter and it takes us to the second post we wrote.
And this is the code we used inside the app.js:
app.get("/posts/:postName", function(req, res){
const requestedTitle = _.lowerCase(req.params.postName);
posts.forEach(function(post) {
const storedTitle = _.lowerCase(post.title);
if (storedTitle === requestedTitle) {
res.render("post", {title: post.title, content: post.content});
}
});
});
In the app.js code, we see in the app.get /posts/:postName and this is just the name that is going to show in the url, :postName is like a variable and it will store whatever the user writes.
In the second line, we use lodash to rewrite what the user wrote to what we want, for example if the user wrote AnoTheR POst it will automatically change it to another-post, and we store it in a constant called requestedTitle.
Next is a forEach loop on a posts array (where we store every post), and this is just to go throught every post and check the names.
In the 4th line, we are again using lodash for the same thing, but this time arround for the title of each individual post, and storing it in a constant called storedTitle.
And last, an if statement, where if both the names are the same then it will render the post.ejs page, and we just pass down the title and content from the selected post using this code , {title: post.title, content: post.content}.
And this is the code we used inside the post.ejs:
<%- include("partials/header") -%>
<br>
<div class="card">
<h2 class="card-header"> <%= title %> </h2>
<div class="card-body">
<p class="card-text"> <%= content %> </p>
</div>
</div>
<%- include("partials/footer") -%>
As you can see this post.ejs isn't hard to explain, the top and bottom lines where it says include("partials are just the header and footer templates I use, just to save time coding. Whats inside is what the post.ejs will render when it gets called.
I hope it wasn't that confusing, I'm still learning to code and I hope it helps you with what you are looking for. I think this isn't the exact answer for your question, but I think it will help you navigate your way throught.
If you need more explanation or help, this is my instagram: #cemruniversal, I'm always happy to help if I can.
Edit: 30 minutes after original post
I think I found a way it could work, I'll show you a piece of code from the same blog website.
Whenever I want to compose a new post I use this code:
app.get("/compose", function(req, res){
res.render("compose");
});
And obviously there is a form for you to write the post, and after you submit, it sends you to the home page, and saves the post. For that I used this piece of code:
app.post("/compose", function(req, res){
const post = {
title: req.body.postTitle,
content: req.body.postBody
};
posts.push(post);
res.redirect("/");
});
I had an idea for your website, what if when you pressed the Profile button, it renders a specific page on your site, and when you press another button it renders another page. It could work, wouldn't it?
Please try it out and tell me how it went.
I think something like this:
<nav>
<div class="nav-wrapper teal darken-4">
BAZAART
<ul class="right hide-on-med-and-down">
<li><a class="waves-effect waves-light btn teal lighten-1" href="/home"> <i class="material-icons right">home</i> home</a></li>
<li><a class="waves-effect waves-light btn teal lighten-1" href="/profile">profile <i class="material-icons right">account_box</i></a></li>
</ul>
</div>
</nav>

Simple pagination in FreeMarker with Spark Framework

I implement a simple blog use Spark Framework with FreeMarker. I need implement pagination in order to show only 5 entries per page, and it is not necessary to show page numbers, with next and previous buttons would be fine. However, I don't even know where to begin in the pagination. This my current code to show all the entries:
<#list entries as art>
<h2>
${art.getTitle()}
</h2>
<p>
Author: ${art.getAuthor().getName()}
</p>
<p><span class="glyphicon glyphicon-time"></span>${art.getDate()}</p>
<hr>
<#assign body=art.getBody()>
<#if body?length < 70>
${body}
<#else>
${body?substring(0,70) + "..."}
</#if>
<br><br>
<a class="btn btn-primary" href="/Entrada/${art_index}">Read More<span class="glyphicon glyphicon-chevron-right"></span></a>
<hr>
</#list>
Also, here is the backend code in Spark Framework:
get("/Home", (request, response) -> {
Map<String, Object> attributes = new HashMap<>();
attributes.put("entries", entrie.getEntries());
return new ModelAndView(attributes, "index.ftl");
}, freeMarkerEngine);
Any help would be appreciated, thanks in advance!
Usually you paginate before putting the list into the model, because then you can avoid loading the entries that you won't show anyway. So simply only pass the list of entries that you will actually show on the current page (as opposed to the whole list), and also pass a pageNumber and totalPages variable (two numbers) that you can use in the template.
BTW, in the template, art.getAuthor().getName() can be written as art.author.name. body?substring(0,70) can be written as body[0 .. 70].

Paging in Umbraco

I'm working in my Umbraco based website, and I have a page that contains objects arranged in a grid, and the amount of objects is getting bigger so I'll need to create pagination to this page. How can I create the pagination?
I'm new with Umbraco and website development, sorry of this is a stupid question.
Thanks!
Have a look here
#if (Model.HasNext || Model.HasPrevious) {
<nav class="pagination" role="pagination">
#if (Model.HasPrevious) {
<a class="newer-posts" href="#Model.PreviousUrl">
<i class="fa fa-chevron-circle-left"></i> Newer
</a>
}
<span class="page-number">Page #(Model.CurrentPageIndex + 1) of
#Model.TotalPages</span>
#if (Model.HasNext) {
<a class="older-posts" href="#Model.NextUrl">
Older <i class="fa fa-chevron-circle-right"></i>
</a>
}
</nav>
}
This code is from Articulate Blog engine (Umbraco plugin). You must create a custom Pager model.

Using knockoutjs to data-bind list data into bxslider

I have managed to get the code to display list data which is driven from a sharepoint list. The list only contains one column in each row item which is called Title. I need to display the titles through the bxslider, one item per slide.
Usual bxslider html
<ul class="bxslider">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
My html implementing data-bind
<ul class="bxslider" data-bind="foreach: items">
<li data-bind="text: Title"></li>
</ul>
For some reason the 'Titles' are all being generated in one li tag, rather than creating an li tag for each item in the list.
If anyone has come across this problem before or have any advice or suggestions it would be very much appreciated.
View Model
var items = ko.observable();
jQuery(document).ready(function () {
jQuery.getJSON( "ListURLHERE", {}, dataCallBack
);
ko.applyBindings();
});
function dataCallBack(data) {
items(data.d.results);
}
I have found the answer to the problem!
I was initiating the bxslider function before the knockout js code. I had to implement the bxslider function into the dataCallBack function and it worked.
function dataCallBack(data) {
News(data.d.results);
jQuery(document).ready(function(){
jQuery('.bxslider').bxSlider();
});
}
Thanks for your help everyone!

link dont scroll to top of page issue

i need some help, please... I got a affixed menu on my page, and i want to when i click on any item of it, the page scrolls back to the top, i would use an anchor, but i already use it to call the pages on each button...
this is my code
<div class="span1 menu">
<ul class="nav">
<li id='gostou' class='menufixo' title="gostou do filme?"></li>
<li id='evolucao' class='menuacao' title="evolução"></li>
<li id='comentarios' class='menuacao' title="comentários"></li>
<li id='info' class='menuacao' title="informações"></li>
<li id='assistir' class='menuacao' title="cinemas"></li>
<li id='tags' class='menuacao' title="cloud tags"></li>
<div class='ferramentas'></div>
<script>
$(".menu ul").on("click", "li", function()
{
$(this).parent().find("li").removeClass("menufixo").addClass("menuacao");
$(this).toggleClass("menufixo").toggleClass("menuacao");
});
</script>
</ul>
</div>
Thanks in advance!!
from what I've understood based on your "short" requirements.
http://jsfiddle.net/Madthew/NRMhf/
This code is the code used to go to the top of the page (using jQuery):
$('html, body').animate({scrollTop:0}, 'slow');
If you add:
return false;
then your href stop working.
Take a look here regarding how to setup the duration:
http://api.jquery.com/animate/
Instead of using 'fast' and 'slow' you can enter directly the value in millisecond.
The default duration is 400 milliseconds. 'fast' = 200 and 'slow'= 600.
Lower values means faster execution.
In order to let you see that it's working, I just added a div with a fixed height and a black background. When you click to any of the item you scroll to the top.

Resources