Jump to content


PHP/HTML Content Practices

  • Please log in to reply
2 replies to this topic

#1 kid_drew

  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 12 September 2006 - 03:59 AM

Ok, so I'm a veteran programmer beginning to venture into the world of PHP.  I'm looking for an idea of how people go about structuring their files in large projects.  I've heard of people keeping their PHP and HTML code separate, and I really don't understand how that is done seeing as how so much is done inline.  Does everyone just use smarty templates?

What about file structure?  Does everyone have a typical header/body/footer structure where they include/require header and footer files in every page and fill in the content in between?

#2 btherl

  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 12 September 2006 - 09:45 AM

Yep, Smarty templates.  Once you've started you won't be able to stop :)

Headers and footers are usually a good idea.  But it depends a lot on your application.  It might make sense to abstract other things out too.  If you're using Smarty, you can have code in your "display a page" function that adds in the header and footer for every page.  Then there's no need to repeat that code everywhere.  If some pages don't use the standard header/footer, you can set a "don't load header/footer" variable before calling the display function.

The system I work on currently uses apache to rewrite requests like /page.html to use the script page.php and the Smarty template page.html, and call the function page() to get the Smarty variables.  Then to make a new page you just create the template and the associated file, and off you go.

Smarty templates include foreach loops, captures (eg, capture your pagination links and print them at the top and bottom of the page with only one set of code, but all still in the templates), and other nifty stuff.

#3 radalin

  • Members
  • PipPipPip
  • Advanced Member
  • 179 posts

Posted 12 September 2006 - 09:55 AM

smarty is hard. It's not only a template system but also it has its own syntax and abilities. I do not like it a lot. Because it has too many features about logical things in html files.

If there are web designers and web programmers things should be different. And none should do others job. But with smarty, a designer can write it's own logical queries, which I would never prefer.

I use pear's html_template_it which is quite good and only a template system. It's very easy to learn too.
Roy Simkes
Yet Another Parkyeri Developer

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users