php - Converting a site from HTML to Smarty


I have a series of HTML pages which I am converting into Smarty syntax since I've learnt this. This site is a fairly old one in design terms, no include etc. - even though our .htaccess allows us to treat PHP as HTM extension.

I've saved a few as .tpl pages, but what's the best way to go about converting it into full-scale templating?

I've been slowly, but tediously, splitting pages into .tpl files, although not sure if that's the right way to do it... the site is a jointly-created one, dating back to 2006 originally as pure HTML.

I'm using a templating engine because that's what the original site-owner wanted, and we're both competent at using a templating engine.

The manual on Smarty was useful; but I'm wondering how to do a Smarty pagination script where the data is paginated like this for database results (moving some data into a new database that was formerly static data enclosed in < li > tags), rather than 1-10, 11-20 etc.:

If there's another solution (for now we don't quite need CodeIgniter etc.) I'd appreciate the help! ;)




The SmartyPaginate plugin may help. This was written by one of the original Smarty developers. I'm not sure if it is compatible with Smarty 3 though, if that is what you're using.

The other possibility would be to create a template that outputs the pagination, and accepts some parameters to set the options.


{include file="paginator.tpl" curpage="3" perpage="50" numitems="3428" link="showitems.php" param="p"}


curpage = the current page being viewed, this would be set by PHP.

perpage = how many items to show per page - this is probably a static value set by php, or from user preferences

numitems = how many total items there are - this is calculated by php/sql and passed to template

link = the page to link each page to

param = the parameter to use for the page number, this is used by PHP to get the page to be viewed. i.e. items.php?p=1

That said, you would use PHP code to check to see if a page number was set in the URL, and then check to see if the page number is valid and within the acceptable range.

Your actual page content would just loop over an array of items which would be the results from the database. Depending on what set of results was fetched, it will be showing items from the given page.

If the SmartyPaginate plugin won't work, you could probably look at it for help with the process of pagination and adapt it to your needs.

People are also looking for solutions to the problem: building a sql query string with php parameters


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.