php and html organization

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
shamkawai
Forum Newbie
Posts: 7
Joined: Mon Jan 10, 2011 4:09 pm

php and html organization

Post 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.
User avatar
Technical
Forum Commoner
Posts: 81
Joined: Thu Dec 02, 2010 5:30 am

Re: php and html organization

Post by Technical »

You should always use templates. Try Smarty.
shamkawai
Forum Newbie
Posts: 7
Joined: Mon Jan 10, 2011 4:09 pm

Re: php and html organization

Post by shamkawai »

could you elaborate a bit how template works.
i'm new
User avatar
Technical
Forum Commoner
Posts: 81
Joined: Thu Dec 02, 2010 5:30 am

Re: php and html organization

Post by Technical »

Read about Template Engine.
shamkawai
Forum Newbie
Posts: 7
Joined: Mon Jan 10, 2011 4:09 pm

Re: php and html organization

Post by shamkawai »

Thank you.
I am sure iwill hv more questions when I am done reading
ga
Asperon
Forum Newbie
Posts: 2
Joined: Thu Mar 03, 2011 11:44 pm

Re: php and html organization

Post 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.
Kurby
Forum Commoner
Posts: 63
Joined: Tue Feb 23, 2010 10:51 am

Re: php and html organization

Post 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.
Post Reply