views:

1203

answers:

10

In the past I've written sites in ASP.NET just to get nice reusable templating via master pages (layouts) and user controls (partials). I'm talking about sites that have no more complicated code in them than simple variable substitution in templates - I'm just using it to keep my HTML organized. It's great to be able to define the basic layout of your page in one file, and then just fill in the holes for each individual page, re-using some common bits as user controls.

However, I'd rather not continue using Windows hosting, so I'd like to write static pages in PHP, which runs everywhere. In the past I've written myself a poor-man's user control for PHP that just unpacks an array and includes a template, but that's clunky and still requires me to put PHP includes all over my pages. I feel like Smarty or one of the other big templating languages for PHP is overkill for just organizing some "static" pages.

I've considered just doing the pages in Ruby on Rails because I really like HAML/SASS and the layout/partial model, but having a whole rails app for static content seems silly. But I haven't found anything that seems just right in PHP. Can any PHP gurus recommend anything? I want something more sophisticated than "include" but I don't really need much. That said, something that could give me layouts/partials AND HAML/SASS would be heaven. I've looked at phammable but it doesn't look like it solves the layout/partial problem.

Again, I'm not looking for something as complex as Smarty, and I don't want a full CMS. I just want something that will let me properly modularize the HTML of my site. We're talking one step beyond static HTML here.

+2  A: 

I would suggest to you to look at Drupal and its Block templating model. I think its just what you need.

Nikola Stjelja
A: 

Maybe you should take a look at some content management systems. Drupal is famous in PHP.

eed3si9n
A: 

Drupal really is a simple and extensible CMS. There is a learning curve, but it's strengths are that is starts small out of the box and can grow with your needs and the community is pretty tight about the quality of the code that's written (though I personally find that some of the modules get a little two function happy).

They have a simple stripped down version of the Zen theme, that lets you create the HTML you want to use. Time spent learning this CMS is time well spent, especially if PHP is already your native language.

Steve Perks
but I think Drupal is also very much overkill for just mostly static webpages like he requests...
Sander Versluys
I don't think that there is a very clean interim from include to CMS. Like I said, I understand that Drupal has a learning curve, but once understood, and with the modularization, it's extremely strong for using as a base for all all website production.
Steve Perks
I totally agree that Drupal is worth the effort, but in this case i don't think that's what he's looking for. But hey, it's up to him to decide... :-)
Sander Versluys
A: 

From what i understand, you don't want a full fledged cms and no overkill templating engine like Smarty. Php is a templating system and if you want to properly modularize it, that's up to you.

But i understand, those php tags between your html doesn't look pretty. (Although using shorttags minimizes this...)

You can always use PEAR Templating system, it's available by default on most php installations.

I would also recommend the CodeIgniter MCV framework because it's really lightweight. You choose which libraries get autoloaded.

Sander Versluys
+4  A: 

Zend_View supports layouts, partials and placeholders. Also checkout a new templating language called Dwoo which is similar to Smarty but also takes some ideas from Django templating. And finally, Calypso which is a Django template language clone for PHP

ejunker
Can you use Zend_View without having to use everything else? I love working with the Zend Framework, but it's overkill when you only really care about using Zend_View.
Andrew
Yep, you can use almost all Zend Framework's components independently.
Maiku Mori
A: 

About six months ago, I started using the Zend Framework. I got used to working with layouts and partials, and never wanted to go back creating sites without it. But for small sites, ZF is just too bulky. It's overkill to use ZF for a site that could be done in HTML.

Check out EuropaPHP. It's a super lightweight, PHP based layout framework. It's brand new as a framework, but so far, I like it a lot! It allows me to use layouts and doesn't require a huge library and strict rules to achieve the same results.

Andrew
Europa seems like a nice small MVC framework, but that's still too complicated for just putting a static page together.
BRH
+1  A: 

Stacey is about what I was looking for in terms of a simple PHP templating library for static sites. On the Ruby side, there's StaticMatic, which doesn't even require Ruby support on the server since it generates the whole static site. Very nice (especially since it uses HAML) but you can't have any dynamic elements at all.

BRH
+1  A: 

I just want something that will let me properly modularize the HTML of my site.

Look at http://code.google.com/p/hoduli/

With that simple tool you'll be able to write like this:

<h:define name="header">
  some header contents
</h:define>

...

<h:header />

<h:include file="middle_part.php" />

<h:footer>
  some ...
</h:footer>
A: 

PHP Tiles is dedicated to page layout without interfering with your choice of template language, it's a very close clone of Apache Tiles.

It doesn't require you to modify your pages to make use of the templating, so no including necessary.

Evan
A: 

If your looking for something simple I would recommended PHP Template Inheritance. Then you can continue to code in straight php.