Page 1 of 1
php and html organization
Posted: Sat Jan 15, 2011 12:40 am
by shamkawai
I am wondering what is the best way to organize php in your html webpages.
Do you try as much as possible to pack your php code into function (or other ways I am not aware of) so as to limit having a large chuck of php here and there in your html, and replace them by calling upon the function
or php and html are just mixed.
Re: php and html organization
Posted: Sat Jan 15, 2011 12:43 am
by Technical
You should always use templates. Try
Smarty.
Re: php and html organization
Posted: Sat Jan 15, 2011 12:44 am
by shamkawai
could you elaborate a bit how template works.
i'm new
Re: php and html organization
Posted: Sat Jan 15, 2011 1:00 am
by Technical
Re: php and html organization
Posted: Sat Jan 15, 2011 1:08 am
by shamkawai
Thank you.
I am sure iwill hv more questions when I am done reading
ga
Re: php and html organization
Posted: Sun Mar 13, 2011 12:46 pm
by Asperon
The problem with template engines is that some do way too much like Smarty, and others don't do enough. At what point do we stop letting a template engine dictate logic? It can be a slippery slope and create a lot of overhead. At some point, PHP free html becomes more expensive than not having it.
Re: php and html organization
Posted: Fri Mar 25, 2011 11:11 am
by Kurby
Technical wrote:You should always use templates. Try
Smarty.
This isn't entirely true, and Asperon touched on it. "Always" use a template? Hardly. Smarty can over complicate very simple applications. Some will use it as a crutch to ensure that their PHP is separate from their HTML. However, since Smarty can employ quite a bit of logic, it can sometimes only portray an illusion of logic and presentation separation.
The common, and probably least helpful answer, is: "Do what your project requires".
I mainly avoid templates but still try to separate PHP from my HTML. This is done by proper OOP design. Create relevant classes and useful functions. Generally good code design will accomplish what you set out to do with trying to reach ultimate logic/presentation separation: clean and understandable code.