HAML if else bug
Status: Alpha
Brought to you by:
alfanick
%tr
- if (!empty($page->title))
%th Title
- else
%th Title err
%td= $page->title
It is compiled to:
<tr>
<?php if (!empty($page->title)) {?> <th>Title</th>
<?php } ?><?php else {?> <th>Title err</th>
<?php } ?> <td><?php echo $page->title; ?>
</td>
But it doesn't work because of the syntax error:
<?php } ?><?php else {?>
Must be
<?php } else {?>
There is also a problem with nested php.
6 %body
7 %h1= $title
8 %h3= $text
9 -if ($some_condition)
10 %p Short answer
11 -if( $another_conditon )
12 %p more details
produces this:
<?php if ($some_condition) { ?>
<p>
Short answer
</p>
-if( $another_conditon )
<p>
more details
</p>
<p>
more details
</p>
<?php } ?>
A small and dirty fix (file HamlParser.class.php), line 278:
public function compile($sCompiled)
{
/* add this */ $sCompiled = preg_replace('!\?>\s*<\?php!mus', "\n", $sCompiled);