designing a re-usable pager element

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

designing a re-usable pager element

graild
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?

------------------------------------------------------------------------------
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
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Reply | Threaded
Open this post in threaded view
|

Re: designing a re-usable pager element

Daniel Dekany
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
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Reply | Threaded
Open this post in threaded view
|

Re: designing a re-usable pager element

graild
1. I have to caculate the # of pages to display using the total_items and items_per_page variables that I will pass in.

total pages = math.ceiling(total items / items per page)

How can I do the above in freemarker?

2. how to create a loop, that loops x times?  I have only used the #list syntax before.



On Fri, Oct 12, 2012 at 5:31 AM, Daniel Dekany <[hidden email]> wrote:
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
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user


------------------------------------------------------------------------------
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
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Reply | Threaded
Open this post in threaded view
|

Re: designing a re-usable pager element

Daniel Dekany
Friday, October 12, 2012, 10:24:59 PM, S Ahmed wrote:

> 1. I have to caculate the # of pages to display using the
> total_items and items_per_page variables that I will pass in.
>
> total pages = math.ceiling(total items / items per page)
>
> How can I do the above in freemarker?

  <#local totalPages = (totalItems / itemsPerPage)?ceiling>

(Or the same with #assign if it's not inside a macro or function.)

> 2. how to create a loop, that loops x times?  I have only used the #list syntax before.

  <#if (x > 0)>
    <#list 1..x as i>
      ...
    </#list>
  </#if>

(Where the () aroind x > 0 was only needed because otherwise it closes
the tag.)

> On Fri, Oct 12, 2012 at 5:31 AM, Daniel Dekany <[hidden email]> wrote:
> 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
> _______________________________________________
> FreeMarker-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>

--
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
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user