Menu

#1 HAML if else bug

open
nobody
None
5
2009-01-26
2009-01-26
No

%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 {?>

Discussion

  • Nobody/Anonymous

    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 } ?>

     
  • Dmitry

    Dmitry - 2010-08-20

    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);

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.