A CodeIgniter Spark to integrate Haml-To-Php library into Code Igniter the easy way
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



NOTE: Haml-To-Php does not exists anymore. This spark will be left for instructional purpose only. "

What is

A CodeIgniter Spark to integrate Haml-To-Php library into CodeIgniter. Installable via Sparks system ( [http://getsparks.org](http://getsparks.org GetSparks) )


Mainly because haml_sass spark is based on phamlp, which has some serious bugs and is very limited in parsing HAML. You need to use some code conventions which are not of HAML but are needed by phamlp to work properly. And I do not like this. Haml-To-Php instead is fully compliant with HAML language specs ( passes all the test of the ruby gem ).


First of all you must install the spark:
php tools/spark install hamltophp

Then you need to download the Haml-To-Php library. Is developed by Marc Weber, and is actively developed ( he replies at mails very quickly! ). http://haml-to-php.com

In application/config/autoload.php add hamltophp/x.x.x to $autoload['sparks'].

That's it! Now Haml Spark is available

Usage example standalone

Inside a controller you can use a function similar to this:

public function onlyhaml()  {
  // Hamltophp->parse ( $template file, $variable passed to view )
  echo $this->hamltophp->parse("template.haml", array(
    "content" => "this is the content",
    "sidebar" => "this is the sidebar",

Usage with CI Template Class

Actually this Spark is very easy to use with the CI Template Class developed by Colin Williams. His Class has a very nice hook to add custom parsers for views and this makes very easy to add hamltophp parser to CI.

To do this simply add this code in the application/config/template.php file used by CI Template Class to defined the parser to use:
// Added by Haml-To-Php Spark $config['active_template'] = 'haml';

$config['haml']['template'] = 'template.haml';
$config['haml']['regions'] = array(
$config['haml']['parser'] = 'hamltophp';
$config['haml']['parser_method'] = 'parse';
$config['haml']['parse_template'] = TRUE;

This lines tells the Template class to use Hamltophp->parse() to parse template files instead of the CI Parser class. Also enable parsing of the mail template file, so that a template.haml file is usable inside the views folder as main template file.

Usage example with CI Template Class

public function haml()  {
  $data = array(
    "title" => "title added by me",
    'stuff' => 'things'
  // remember to use Template->parse_view() to parse view file instead of write/write_view
  $this->template->parse_view('content', 'content.haml', $data);
  $this->template->parse_view('sidebar', 'sidebar.haml', $data);

  $this->template->render(); // Just render the 'content' region


CodeIgniter Template Class ( by Colin Williams ) this is optional http://williamsconcepts.com/ci/codeigniter/libraries/template/

Haml To Php Library ( by Marc Weber ) this is required ( see setup ) http://haml-to-php.com