| | 1268 | * Sets content passed in or echoed after calling this function and sets it |
| | 1269 | * to a variable named $content_for_"$name" to be used in the layout. |
| | 1270 | * Example: |
| | 1271 | * View: |
| | 1272 | * <? $this->content_for("navigation") ?> |
| | 1273 | * <li><?= link_to('Login', array(":action" => 'login')) ?></li> |
| | 1274 | * <? $this->end_content_for() ?> |
| | 1275 | * Layout: |
| | 1276 | * <?= $content_for_navigation ?> |
| | 1277 | * |
| | 1278 | * @param string $name variable name to be set for use in layout |
| | 1279 | * @param string $content (optional) content for the variable to be set |
| | 1280 | */ |
| | 1281 | function content_for($name, $content = null) { |
| | 1282 | array_push($this->content_for_open_blocks, $name); |
| | 1283 | ob_start(); |
| | 1284 | if($content) { |
| | 1285 | echo $content; |
| | 1286 | } |
| | 1287 | } |
| | 1288 | |
| | 1289 | /** |
| | 1290 | * Ends an open block call by content_for() and sets the content of the buffer |
| | 1291 | * to the variable $content_for_"name" |
| | 1292 | */ |
| | 1293 | function end_content_for() { |
| | 1294 | if(count($this->content_for_open_blocks)) { |
| | 1295 | if($name = array_pop($this->content_for_open_blocks)) { |
| | 1296 | $content = ob_get_contents(); |
| | 1297 | ob_end_clean(); |
| | 1298 | $this->{"content_for_".$name} = $content; |
| | 1299 | } else { |
| | 1300 | ob_end_clean(); |
| | 1301 | } |
| | 1302 | } |
| | 1303 | } |
| | 1304 | |
| | 1305 | /** |