Skip to content

Commit

Permalink
Added content_for() helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Matěj Grabovský authored and Fabrice Luraine committed Nov 6, 2009
1 parent 0422dc3 commit de14f67
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
1 change: 0 additions & 1 deletion TODO
Expand Up @@ -28,7 +28,6 @@

## Later ##

- create capture helpers `content_for($name) ... end_content_for()`. That will help sending content from views to layout
- add routing support for dispatching to class methods: `dispatch('/hello/:name', 'Hello::who');`
- add routing support for dispatching to lambdas/closures (requires PHP 5.3.0): `dispatch('/hello/:name', function(){ # ... });`.

Expand Down
32 changes: 32 additions & 0 deletions lib/limonade.php
Expand Up @@ -1364,6 +1364,38 @@ function render_partial($content_or_func, $locals = array()) {
return render($content_or_func, null, $locals);
}

/**
* Starts capturing block of text
*
* Calling with params stops capturing (same as end_content_for())
*
* @param string $name
* @return void
*/
function content_for($name = null) {
static $_name = null;
if(is_null($name)) {
set($_name, ob_get_clean());
$_name = $name;
} else {
$_name = $name;
ob_start();
}
}

/**
* Stops capturing block of text
*
* Stops capturing block of text and puts the captured content
* to a variable (name is defined as first param of content_for())
* for later use in layouts.
*
* @return void
*/
function end_content_for() {
content_for(null);
}

/**
* Returns html output with proper http headers
*
Expand Down

0 comments on commit de14f67

Please sign in to comment.