Re: designing a re-usable pager element
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Friday, October 12, 2012, 3:39:59 AM, S Ahmed wrote: > I want to create a re-usable content piece that will display a pager, my html looks like: > > <div class="pagination"> > <ul> > <li><a href="">Prev</a></li> > <li class="active"><a href="">1</a></li> > <li><a href="">2</a></li> > <li><a href="">3</a></li> > <li><a href="">Next</a></li> > </ul> > </div> > > Now to make it re-usable, I want to pass in the following information: > > 1. base_url e.g. www.example.com/post/list > 2. current_page e.g. 3 > 3. total items e.g. 100 > 4. items per page e.g. 25 > > So given this information, I should see 4 page links (100 items / 25 = 4): > > > <div class="pagination"> > <ul> > <li><a > href="www.example.com/post/list?page=2">Prev</a></li> > <li><a href="www.example.com/post/list?page=1">1</a></li> > <li><a href="www.example.com/post/list?page=2">2</a></li> > <li class="active"><a > href="www.example.com/post/list?page=3">3</a></li> > <li><a href="www.example.com/post/list?page=4">4</a></li> > <li><a > href="www.example.com/post/list?page=4">Next</a></li> > </ul> > </div> > > > How could I create a macro for this in freemarker? Where exactly you stuck in doing this? (Also, to answer this, one should know how the data-model looks like. I suppose the number of pages and the current page number is not calculated by FreeMarker, but is coming through the data-model.) -- Best regards, Daniel Dekany ------------------------------------------------------------------------------ Don't let slow site performance ruin your business. Deploy New Relic APM Deploy New Relic app performance management and know exactly what is happening inside your Ruby, Python, PHP, Java, and .NET app Try New Relic at no cost today and get our sweet Data Nerd shirt too! http://p.sf.net/sfu/newrelic-dev2dev