sfHamlView plugin
Overview
This plugin gives you the ability to use the Haml template engine (originally in Ruby)
with your symfony project. http://haml.hamptoncatlin.com/docs/haml
Installation
To install sfHamlView:
$ php symfony plugin-install http://plugins.symfony-project.com/sfHamlViewPlugin
Alternatively, if you don't have PEAR installed, you can download the latest package attached to this plugin's wiki page and extract it under your project's plugins/ directory.
Or you can use the SVN repository http://svn.komapa.com/sfhamlview
Clear the cache to enable the autoloading to find the new classes:
$ php symfony cc
Usage
There has been for quite some time now Haml for Ruby (ROR) and I was impressed by the fact that it can solve my problems of badly formated and erroneous HTML code and also I could not get the designers write XHTML code and make easy to maintain.
I know about the project http://phphaml.sf.net but when I took a look at the source code I was not impressed by the quality and also it did not fit well with making it symfony template view. In the beginning I tried to fix it but when into a big vicious circle and decided to port Haml by myself.
So the Haml parser used in sfHamlViewPlugin is not a project by itself (although it is simple one class file) but rather available only in this plugin. I plan to make its own project and just include it with sfHamlView.
Now about the usage :) The official Haml documentation is at http://haml.hamptoncatlin.com/docs/haml
I will only point here what are the differences/limitations of the PHP port of the parser.
Differences
- All Ruby specific features are not available for obvious reasons.
- The “[]†(square brackets syntax) is not implemented yet.
- Filters are not implemented yet.
- The “==†syntax is not implemented as it makes sense only in Ruby
Limitations
- When you define tag attributes you MUST use single quotes. For example:
%div{:id => 'collection'}
%div{:class => 'item'}
%div{:class => 'description'} What a cool item!
and not
%div{:id => "collection"}
%div{:class => "item"}
%div{:class => "description"} What a cool item!
- The XML generation is in no way tested enough because I have no need currently for it. The code is all there but there are small glitches that need to be sorted out and tested so for not usage of “!!! XML†is not recommended. (all other features are available like “!!! Strict iso-8859-1“)
- When you use blocks like if, foreach, for, etc, you need to close the block explicitly. For example:
* if ($foo)
%div.bar Hello Here
* else
%div.baz Hello There
* endif
Example Usage
!!!
%html
%head
= include_http_metas()
= include_metas()
= include_title()
%link{:rel => "shortcut icon", :href => "/favicon.ico"}
* if (@$autodiscovery)
= auto_discovery_link_tag('rss', $autodiscovery[array("type" => 'application/atom+xml', 'title' => $autodiscovery["title"]("link"],))
* endif
/
[lt IE 7](if)>
<link rel="stylesheet" type="text/css" href="/css/ie6fix.css" />
<![endif]
%javascript
function antispam(ext,domain,name) {
document.write('<a href="mailto:' + name + '@' + domain + '.' + ext + '">');
document.write(name + '@' + domain + '.' + ext + '</a>');
}
%body
#doc.yui-t7
#hd{:style => "background: url(/pics/top-orange-band.gif) left top #EE9933; width: 780px"}
#header{ :style => "width: 780px;" }
#branding
= link_to(image_tag("/pics/logo.gif"), "/")
* if (@$trivia)
%br
%br
%span
%font{:size => "3"} Did you know...
%br
%font{:size => "2"}
= $trivia->getContent()
* endif
#bd
.yui-g{:style => "background: #E9B26E; width: 780px"}
= include_partial('global/main_navigation')
.yui-g{:style => "background: #fff"}
= $sf_data->getRaw('sf_content')
%br
%br
#ft
= include_partial('global/main_footer')
License
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.