Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Html Style attributes ()

svallory edited this page Jul 5, 2012 · 2 revisions

Html style attributes are simpler than attribute hashes. See below what they can do.

  • Can be stretched across multiple lines

    Just like hash-style attributes. The follow HamlPHP snippet

      %script(type="text/javascript"
              src="javascripts/script_#{2 + 7}")

    will compile to

      <script type="text/javascript" src="javascripts/script_<?php echo 2 + 7; ?>" />
  • Variables can be used by omitting the quotes

      %a(title=$title href=$href) Stuff

    compiles to

      <a <?php atts(array('title' => $title, 'href' => $href)); ?>>Stuff</a>
  • Can be written just like HTML:

      %input(selected)

    compiles to:

      <input selected="selected"></input>
  • But more complicated expressions aren’t allowed.

    For those you’ll have to use the {} syntax. You can, however, use both syntaxes together.

      %a(title=$title){href => $link->href} Stuff

    compiles to:

      <a <?php atts(array('title' => $title, 'href' => $link->href)); ?>>Stuff</a>
Clone this wiki locally