Example #1
0
        }
        $this->current_block = $name;
        ob_start();
    }
    /** Stop the definition of a block. Name is optional. */
    private function endBlock($name = null)
    {
        if (empty($this->current_block)) {
            throw new TemplateException('No block was opened.');
        }
        if (!is_null($name) && $name != $this->current_block) {
            $msg = "Closing a block that wasn't open in the first place ({$name} " . "closed, but {$this->current_block} was open).";
            throw new TemplateException($msg);
        }
        $content = ob_get_contents();
        ob_end_clean();
        $this->parent->assignBlock($this->current_block, $content);
        $this->current_block = '';
    }
    /** Print a block if it exists. */
    private function block($key)
    {
        echo isset($this->blocks[$key]) ? $this->blocks[$key] : '';
    }
}
// default template functions
Template::$functions = array('get' => function ($template, $key, $default = null) {
    return $template->get($key, $default);
}, 'encode' => function ($template, $string) {
    return Template::encode($string);
});