2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4 // +----------------------------------------------------------------------+
5 // | Akelos Framework - http://www.akelos.org |
6 // +----------------------------------------------------------------------+
7 // | Copyright (c) 2002-2006, Akelos Media, S.L. & Bermi Ferrer Martinez |
8 // | Released under the GNU Lesser General Public License, see LICENSE.txt|
9 // +----------------------------------------------------------------------+
14 * @author Bermi Ferrer <bermi a.t akelos c.om>
15 * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org
16 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html>
21 * Capture lets you extract parts of code into instance variables which
22 * can be used in other points of the template or even layout file.
24 * == Capturing a block into an instance variable
26 * <?php $capture_helper->begin (); ?>
28 * <?php $script = $capture_helper->end (); ?>
31 * == Add javascript to header using content_for
33 * $capture_helper->content_for("name"); is a wrapper for capture which will store the
34 * fragment in a instance variable similar to $content_for_layout.
38 * <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
40 * <title>layout with js</title>
41 * <script type="text/javascript">
42 * {content_for_script}
46 * {content_for_layout}
52 * This page shows an alert box!
54 * <?php $capture_helper->begin ('script'); ?>
55 * alert('hello world');
56 * <?php $capture_helper->end (); ?>
62 var $_stack = array();
64 * Capture allows you to extract a part of the template into an
65 * instance variable. You can use this instance variable anywhere
66 * in your templates and even in your layout.
70 * <?php $capture_helper->begin(); ?>
71 * Welcome To my shiny new web page!
72 * <% $greeting = $capture_helper->end(); ?>
74 function begin ($var_name = '')
77 $this->_stack
[] = $var_name;
80 function end($add_to_view = true)
82 $var_name = array_pop($this->_stack
);
83 $result = ob_get_clean();
84 if($add_to_view && !empty($var_name)){
85 $this->_addVarToView('content_for_'.$var_name, $result);
90 function _addVarToView($var_name, $content)
92 AkActionView
::_addGlobalVar($var_name, $content);
96 * Content_for will store the given block
97 * in an instance variable for later use in another template
100 * The name of the instance variable is content_for_<name>
101 * to stay consistent with $content_for_layout which is used
102 * by ActionView's layouts
106 * <?php $capture_helper->content_for('header'); ?>
107 * alert('hello world');
108 * <?php $capture_helper->end(); ?>
110 * You can use $content_for_header anywhere in your templates.
112 * NOTE: Beware that content_for is ignored in caches. So you shouldn't use it
113 * for elements that are going to be fragment cached.
115 function content_for($name)