Skip to content

Commit

Permalink
Tweaked content_for to work more like the Rails' one – added second p…
Browse files Browse the repository at this point in the history
…arameter $content
  • Loading branch information
Matěj Grabovský authored and Fabrice Luraine committed Nov 7, 2009
1 parent de14f67 commit c050f63
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lib/limonade.php
Original file line number Diff line number Diff line change
Expand Up @@ -1367,33 +1367,36 @@ function render_partial($content_or_func, $locals = array()) {
/**
* Starts capturing block of text
*
* Calling with params stops capturing (same as end_content_for())
* Calling with params stops capturing (same as end_content_for()).
* After capturing the captured block is put into a variable
* named $name for later use in layouts. If second parameter
* is supplied, its content will be used instead of capturing
* a block of text.
*
* @param string $name
* @param string $content
* @return void
*/
function content_for($name = null) {
function content_for($name = null, $content = null) {
static $_name = null;
if(is_null($name)) {
if(is_null($name) && !is_null($_name)) {
set($_name, ob_get_clean());
$_name = $name;
} else {
$_name = null;
} elseif(!is_null($name) && !isset($content)) {
$_name = $name;
ob_start();
} elseif(isset($name, $content)) {
set($name, $content);
}
}

/**
* 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);
content_for();
}

/**
Expand Down

0 comments on commit c050f63

Please sign in to comment.