CodeIgniter Forums
Symfony Slot - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Symfony Slot (/showthread.php?tid=43977)



Symfony Slot - El Forum - 07-29-2011

[eluser]Andrew H L Leung[/eluser]
Slot Helper:

Introduction
Symfony Slot like function.
http://www.symfony-project.org/book/1_0/07-Inside-the-View-Layer#chapter_07_sub_slots

Require library
http://codeigniter.com/wiki/layout_library/

Source
helpers/slot_helper.php
Code:
<?php
function slot($name){
    Slot::setName($name);
    ob_start();
}
function end_slot(){
    $name=Slot::getName();
    Slot::set($name,ob_get_contents());
    ob_end_clean();
}
function get_slot($name,$default=''){
    return ( Slot::get($name)==false )?$default:Slot::get($name);
}
class Slot{
    static $name='';
    static $content=array();
    static function setName($in){
        self::$name=$in;
    }
    static function getName(){
        return self::$name;
    }
    static function set($key,$val){
        self::$content[$key].=$val;
    }
    static function get($key){
        if( !isset(self::$content[$key]) ){
            return false;
        }
        return self::$content[$key];
    }
}

?>

Usage
template.php
Code:
<html >
<head>
<title><?php echo get_slot('html_title',''); ?></title>  
<?php echo get_slot('html_head',''); ?>
</head>
<body>
<?php echo get_slot('html_body',''); ?>
</body>
</html>

view_file.php
Code:
<?php slot('html_title'); ?>
I am page title.
<?php end_slot(); ?>

<?php slot('html_head'); ?>
<!-- Hi! This content will be show inside head tag. -->
<?php end_slot(); ?>

<?php slot('html_body'); ?>
Hi! This content will be show inside body tag.
<?php end_slot(); ?>

Output
Code:
<html >
<head>
<title>
I am page title.
</title>
<!-- Hi! This content will be show inside head tag. -->
</head>
<body>
Hi! This content will be show inside body tag.
</body>
</html>



Symfony Slot - El Forum - 07-29-2011

[eluser]Glazz[/eluser]
Hello,

Im sorry but i dont see the point of this helper lol


Symfony Slot - El Forum - 07-29-2011

[eluser]Andrew H L Leung[/eluser]
see the description of symfony slot.
http://www.symfony-project.org/book/1_0/07-Inside-the-View-Layer#chapter_07_sub_slots