views:

1965

answers:

6

I'm considering Haml as a templating engine to use with PHP (via phammable).

Do you know any potential drawbacks to using it? Googling seems to glorify it too much, all that markup haiku thing.

+3  A: 

The worst con against things like this is that your designers will have a hard time changing the layout. It all depends on team size, type of project, etc. But if it's only you that will be working with the layout files then just take whatever template system floats your boat in the end - it doesn't matter that much in the long run anyway.

thr
This is weird, designers are people too, and they can learn new things as well - not only programmers are capable to do that.
Evgeny
Actually, Haml vastly simplifies page markup making it much easier for designers to work with the pages. I know this from extensive first-hand experience.
Ethan
"...designers are people too..."Best.Comment.Ever.
Erik Escobedo
A: 

Template 'languages' have a certain limit of helpfulness. The examples look good but it's never like that in the real cases.

If your templates are so complex that they need to be simplified by a 'template system' then you should try to reduce their complexity by feeding them simpler data structures and/or splitting your template in smaller partial templates.

Edward Hyde
Thing id - HAML is not a "template system", its a DSL for writing HTML ... a completely different thing actually.
Evgeny
In my experience I found by actually using Haml that the examples on the site were very representative.
Ethan
@Hyde the templates are not complex. It is just that they are needlessly wordy and repetitive. Wordy and repetitive is great from the perspective of the computer reading and writing it, but it is a PITA from the perspective of people having to read and write it.
Justice
A: 

In my opinion Haml is little useful even in Ruby version, but I agree that some may want to have everything in Ruyb, but it makes even less sense in PHP - the languages that was conceived with the purpose to work closely with HTML. I really see no benefits you could get from yousin PHP version of Haml. Why make simple thing complex?

Rimantas
While I can understand your confusion because PHP is itself a kind of template system (or started as one), templating systems like Smarty and HAML protect you from yourself by forcing you to separate your logic from your views. PHP by itself does not do this. It'll happily let you make a big tangled mess. You might find this more "flexible" and that's okay, but don't knock templates just because you don't like/implement best practices. HAML goes a step beyond templates in that it makes the markup even simpler and forces you to separate stylesheets from semantic markup.
pbhogan
He actually didn't advocate bad practices. I think if you use a templating language to protect your code from yourself you have more problems than a templating language can fix. I for one, despise Smarty, but love Haml. They are two completely different implementations. Smarty is a templating system and language, Haml is a DSL for HTML and quite similar in a lot of ways to YAML.
Tres
+9  A: 

Haml is best experienced by taking it for a test drive, feel how it rolls. Take a view and convert it to Haml. Try StaticMatic if you have Ruby installed, too. If you like how templates look like, use it -- because of yourself, not because of the hype.

But don't forget that the hype is here not by itself, but because Haml and Sass are pretty awesome.

mislav
+1 for HAML and SASS, they are excellent. But you definitely need to consider whether they are right for you first.
Sam Murray-Sutton
+6  A: 

I've been using Haml day after day for over a year. Before that I put in about five years of using JSP and PHP.

Use Haml.

One of the main advantages is that you can express exactly the same page structure and logic with much less code. In pure HTML and in "templating systems" based on it such as JSP, PHP, erb, etc., you have to type hundreds of < and > chars and additional chars to delimit areas of HTML from areas of programming language code. And you have to type opening and closing tags. Before long you wind up with a bewildering thicket of code that's painful and exhausting to maintain. But you sort of get used to it so after doing that for a while you kind of don't realize what a miserable experience the whole thing is.

Haml uses a much simpler system. You open a tag like this:

%p

Put stuff inside it like this:

%p
  Bla bla bla.

That's a lot easier to type and to read than this:

<p>Bla bla bla</p>

What's inside of what is controlled by indentation:

%table
  %tr
    %td
      Bla bla bla.
    %td
      %p
        Hey now.
      %p
        Right on.

Include output from variables like this:

%p
  = some_variable

It's not just easier because there are fewer characters. It's also easier because there are fewer weird characters that are hard to type. Might not sound like a big deal, but multiply "easier" by 10,000 times per day and it really makes a difference.

Haml is extremely easy to learn. The entire format is completely described on one page of their website. I picked it up in about 15 minutes. There are a few nuances that take a little more effort, but you can start doing useful work in Haml almost immediately.

Ethan
A: 

Haml not really DRY that's why I make my own, W2tags and the demo is here, for example:

%ul
  %li.menu.item menu 1
  %li.menu.item menu 2
  %li.menu.item menu 3

in my implementation I make a macro tag (!H!..) and use it:

!H!_li
 %li.menu.item $0

%ul
  -li menu 1;menu 2;menu 3

or you can code like this

%ul
  -li menu 1;\
      menu 2;\
      menu 3
wharsojo