Q:

Why we go for template files and why we go for theme function?

Possible Duplicate:
When should I add a new tpl.php file, and when should I implement a theme function? 

To theme a form: There are two ways.

using function theme_themename_form($form)
Assigning to a variable in preprocess and printing it in the template files.

My question is:

Why two ways?
Which way is best for which case ?
That is for which type of cases we should go for function theme and for which cases we should go for template files.
What is all time best way?

A:

I always think of it like this:
If you need to write a fair bit of HTML for your theme then you want a template file. This way you can maintain as much separation HTML and PHP as you'd like.
If you theme is just accepting data and putting that data through (say) another theme function, then you're not going to be writing any/much HTML. In this case a theme_* function is more appropriate in my opinion.
I don't think there really is an "all time best way", both methods are appropriate for different situations.

