GithubHelp home page GithubHelp logo

ygelfand / ci-spark-hamltophp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from endorama/ci-spark-hamltophp

1.0 2.0 0.0 79 KB

A CodeIgniter Spark to integrate Haml-To-Php library into Code Igniter the easy way

ci-spark-hamltophp's Introduction

What is

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

Why

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

Setup

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(
   'header',
   'content',
   'sidebar',
   'footer',
);
$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
}

Dependencies

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.