Jump to content

PHP/HTML Content Practices


kid_drew

Recommended Posts

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?
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.