Home > Back-end >  Smarty foreach from 0 to a number
Smarty foreach from 0 to a number

Time:12-13

I am trying to create a pagination on a template. I need a helping hand. I have a total page count: $numberOfPage. I would like to loop over it to display my pages. However, it is a number and not an array. I don't know how to make it loop between "1" and my total page count to create my navigation.

Here is the piece of code I created. Thanks for any help.

                    <ol >
                    {foreach $numberOfPage as $page }
                        {dump($numberOfPage)}
                        {if !$page@first}
                            <li>
                                <a href="#" >
                                    <span ></span>
                                    Préc.
                                </a>
                            </li>
                            <li>
                                <a href="#" >{$page-1}</a>
                            </li>
                        {/if}
                        <li>
                            <a href="#" >{$page}</a>
                        </li>
                        {if !$page@last}
                            <li>
                                <a href="#" >{$page 1}</a>
                            </li>
                            <li>
                                <a href="#" >
                                    Suiv.
                                    <span ></span>
                                </a>
                            </li>
                        {/if}
                    {/foreach}
                </ol>

CodePudding user response:

Smarty provides a for function.

  • Related