<?Chano::block('title')?>This is my<?Chano::endblock()?>
<?Chano::extend()?> <?Chano::block('title')?><?php echo Chano::super; ?> blog<?Chano::endblock()?> <?Chano::endextend()?><?require dirname(__FILE__) . '/d.php'?>
/** * Ends a block. If inside an <?Chano::extend()?><?Chano::endextend()?> * section and the block has content, store that content for later use. If * not, check if the current block is extended, if it is output the extended * content, else output the content of the current block. */ static function endblock() { $content = ob_get_clean(); $has_content = trim($content) !== ''; $is_extended = isset(self::$blocks[self::$active_block]); if (self::$inside_extend) { if (!$is_extended && $has_content) { self::$blocks[self::$active_block] = $content; } } else { if ($is_extended) { if ($has_content) { echo str_replace(self::super, $content, self::$blocks[self::$active_block]); } else { echo self::$blocks[self::$active_block]; } unset(self::$blocks[self::$active_block]); } else { if ($has_content) { echo $content; } } } self::$active_block = null; }
static function is_match($items) { return $items instanceof Traversable; } static function get_instance($items) { // ArrayObjects can be used by foreach but cannot be used as an iterator // so we need to get the real iterator. if ($items instanceof ArrayObject) { return $items->getIterator(); } else { return $items; } } } // Register this iterator with Chano. Chano::register_iterator('Chano_Iterators_Iterator'); class Chano_Iterators_Object implements Chano_Iterators_Interface { static function is_match($items) { return $items instanceof stdClass; } static function get_instance($items) { return new ArrayIterator($items); } } // Register this iterator with Chano. Chano::register_iterator('Chano_Iterators_Object');
static function block($name) { ob_start(); self::$active_block = $name; return self::block_is_on(); }
<?Chano::blocks()?> <?Chano::block('title')?>My amazing blog<?Chano::endblock()?> <?Chano::block('content')?> <h2>Entry one</h2> <p>This is my first entry.</p> <h2>Entry two</h2> <p>This is my second entry.</p> <?Chano::endblock()?> <?Chano::endblocks()?> <?require 'base.php'?>
<?Chano::extend()?> <?Chano::block('title')?>B_TITLE <?Chano::endblock()?> <?Chano::block('content')?>B_CONTENT <?Chano::endblock()?> <?Chano::block('footer')?> <?Chano::endblock()?> <?Chano::endextend()?><?require 'a.php'?>
<!DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" href="style.css" /> <title><?Chano::block('title')?>My amazing site<?Chano::endblock()?></title> </head> <body> <div id="sidebar"> <?Chano::block('sidebar')?> <ul> <li><a href="/">Home</a></li> <li><a href="/blog/">Blog</a></li> </ul> <?Chano::endblock()?> </div> <div id="content"> <?Chano::block('content')?> <?if(Chano::block_is_on()):?> My slow content. <?sleep(10)?> <?endif?> <?Chano::endblock()?> </div> </body> </html>