Navigation

More:





Impressum

Examples

1 get the wave
2 automatic quoting
3.1 filters javascript
3.2 filters css
3.3 filters plain
3.4 filters escaped
4.1 loops foreach
4.2 if then else
4.3 loops for
5 how php to haml handles attributes
6 (conditional) comments

Example: 1 get the wave.haml

HAML (written by a designer or programmer)
%h2 That's the wave - get it
%div
  %p
    indentation represents relation %p
    is indented more than the %div
    thus its a child of it.
    Same applies to this text.
  %p within a p tag
  %p
    PHP-TO-HAML get's out of the way.
    It helps you focus on your real job rather
    than on nasty PHP details

HTML (generated by the resulting PHP code)
<h2> That&#039;s the wave - get it

</h2>
<div>
  <p>indentation represents relation %p
is indented more than the %div
thus its a child of it.
Same applies to this text.

  </p>
  <p> within a p tag

  </p>
  <p>PHP-TO-HAML get&#039;s out of the way.
It helps you focus on your real job rather
than on nasty PHP details


  </p>
</div>

Ergebnis:

That's the wave - get it

indentation represents relation %p is indented more than the %div thus its a child of it. Same applies to this text.

within a p tag

PHP-TO-HAML get's out of the way. It helps you focus on your real job rather than on nasty PHP details



Example: 2 automatic quoting.haml

HAML (written by a designer or programmer)
%span='this is an arbitary HTML expression'
%span='<> See how this gets quoted'
%span!='<b>unquoted bold text</b>'
%div
  ="this works :-)\n"
  =strtoupper("this too")."\n"
  inerpolation quoted always eg #{'</>'}
%span='Note: '.substr('Ecomplicated php expression',1)

HTML (generated by the resulting PHP code)
<span>this is an arbitary HTML expression 
</span>
<span>&lt;&gt; See how this gets quoted 
</span>
<span><b>unquoted bold text</b> 
</span>
<div>this works :-)
 THIS TOO
 inerpolation quoted always eg &lt;/&gt;
</div>
<span>Note: complicated php expression 
</span>

Ergebnis:
this is an arbitary HTML expression <> See how this gets quoted unquoted bold text
this works :-) THIS TOO inerpolation quoted always eg </>
Note: complicated php expression


Example: 3.1 filters javascript.haml

HAML (written by a designer or programmer)
:javascript
  // this code will be put into a JS tag
  dosmething('foo');

HTML (generated by the resulting PHP code)
<script type='text/javascript'>
  //<![CDATA[
    // this code will be put into a JS tag
dosmething('foo');


  //]]>
</script>



Example: 3.2 filters css.haml

HAML (written by a designer or programmer)
:css
  // same for CSS rules

HTML (generated by the resulting PHP code)
<style type='text/css'>
  /*<![CDATA[*/
    // same for CSS rules


  /*]]>*/
</style>



Example: 3.3 filters plain.haml

HAML (written by a designer or programmer)
%div
  :plain
    Indentation also applies to filters.

    You can text which will be inserted verbatim here
    Text within filters may contain interpolations:
    #{'<>'} #{3*7} #{count(array(1,2,3))}

    No quoting takes place
    <a href="www.google.com">GOOGLE</a>
    unless you you use the escaped filter:

HTML (generated by the resulting PHP code)
<div>Indentation also applies to filters.

You can text which will be inserted verbatim here
Text within filters may contain interpolations:
<> 21 3

No quoting takes place
<a href="www.google.com">GOOGLE</a>
unless you you use the escaped filter:

</div>



Example: 3.4 filters escaped.haml

HAML (written by a designer or programmer)
:escaped
      <a href="www.google.com">GOOGLE</a>

HTML (generated by the resulting PHP code)
&lt;a href=&quot;www.google.com&quot;&gt;GOOGLE&lt;/a&gt;




Example: 4.1 loops foreach.haml

HAML (written by a designer or programmer)
%h1 foreach
%ul
  -foreach(array(1,2) as $nr)
    %li=$nr

HTML (generated by the resulting PHP code)
<h1> foreach

</h1>
<ul>    <li>1 
    </li>    <li>2 
    </li></ul>

Ergebnis:

foreach



Example: 4.2 if then else.haml

HAML (written by a designer or programmer)
%h1 assign vars and add conditinoal HTML code
- $pred = true;
- if ($pred)
  %div true
- else
  %div
    false (note that closing of else
    branch depends on indentation only!)

HTML (generated by the resulting PHP code)
<h1> assign vars and add conditinoal HTML code

</h1>  <div> true

  </div>

Ergebnis:

assign vars and add conditinoal HTML code

true


Example: 4.3 loops for.haml

HAML (written by a designer or programmer)
%h1 or use a simple for loop
- for($i=0; $i<3; $i++)
    =$i.' '


HTML (generated by the resulting PHP code)
<h1> or use a simple for loop

</h1>0  1  2  

Ergebnis:

or use a simple for loop

0 1 2


Example: 5 how php to haml handles attributes.haml

HAML (written by a designer or programmer)
%h1 
  CSS selector like div attributes can
  be provided this way:
#container.container
  ...

%h1 HTML like attributes
Note how duplicates are removed from the class attribute:
%a(class="foo bar foo") link
%a(href="# looser" href="# winner") link

%h1 Ruby Hash like attributes
Note how duplicates are removed from the class attribute:
%a{:href=>"#", :class=>["a", "list", "bar"]} link

%h1 You can also use interplation within attribute names:
%div{"_#{3*7}" => "really wired attribute!"}

%h1 And of course you can mix both styles:
%h(target="_blank"){:href => "href value"} link

HTML (generated by the resulting PHP code)
<h1>CSS selector like div attributes can
be provided this way:

</h1>
<div class='container' id='container'>...


</div>
<h1> HTML like attributes

</h1>Note how duplicates are removed from the class attribute:

<a class='bar foo'> link

</a>
<a href='# winner'> link

</a>
<h1> Ruby Hash like attributes

</h1>Note how duplicates are removed from the class attribute:

<a class='a bar list' href='#'> link

</a>
<h1> You can also use interplation within attribute names:

</h1>
<div _21='really wired attribute!'>
</div>
<h1> And of course you can mix both styles:

</h1>
<h target='_blank' href='href value'> link

</h>



Example: 6 (conditional) comments.haml

HAML (written by a designer or programmer)
This will only be rendered for IE:
/[if IE]
  %p IE only

-# This won't be rendered at all

/ this will be rendered as HTML comment

HTML (generated by the resulting PHP code)
This will only be rendered for IE:
<!--[if IE]>
  <p> IE only

  </p><![endif]--><!-- this will be rendered as HTML comment
-->

Ergebnis:
This will only be rendered for IE:


Next: Try Online