From de14f67ccee76183395ed847aab28d0426dbc154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Grabovsk=C3=BD?= Date: Sun, 1 Nov 2009 03:12:19 +0800 Subject: [PATCH] Added content_for() helper --- TODO | 1 - lib/limonade.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index 0185fdc..a887935 100644 --- a/TODO +++ b/TODO @@ -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(){ # ... });`. diff --git a/lib/limonade.php b/lib/limonade.php index ce5e758..048d650 100644 --- a/lib/limonade.php +++ b/lib/limonade.php @@ -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 *