[ Index ]

PHP Cross Reference of Akelos Framework

title

Body

[close]

/AkActionView/helpers/ -> capture_helper.php (summary)

(no description)

Author: Bermi Ferrer
Copyright: Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org
License: GNU Lesser General Public License
File Size: 121 lines (4 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

CaptureHelper:: (4 methods):
  begin()
  end()
  _addVarToView()
  content_for()


Class: CaptureHelper  - X-Ref

Capture lets you extract parts of code into instance variables which
can be used in other points of the template or even layout file.

== Capturing a block into an instance variable

<?php $capture_helper->begin (); ?>
[some html...]
<?php $script = $capture_helper->end (); ?>


== Add javascript to header using content_for

$capture_helper->content_for("name"); is a wrapper for capture which will store the
fragment in a instance variable similar to $content_for_layout.

layout.tpl:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>layout with js</title>
<script type="text/javascript">
{content_for_script}
</script>
</head>
<body>
{content_for_layout}
</body>
</html>

view.tpl

This page shows an alert box!

<?php $capture_helper->begin ('script'); ?>
alert('hello world');
<?php $capture_helper->end (); ?>

Normal view text
begin($var_name = '')   X-Ref
Capture allows you to extract a part of the template into an
instance variable. You can use this instance variable anywhere
in your templates and even in your layout.

Example:

<?php $capture_helper->begin(); ?>
Welcome To my shiny new web page!
<% $greeting = $capture_helper->end(); ?>

end($add_to_view = true)   X-Ref
No description

_addVarToView($var_name, $content)   X-Ref
No description

content_for($name)   X-Ref
Content_for will store the given block
in an instance variable for later use in another template
or in the layout.

The name of the instance variable is content_for_<name>
to stay consistent with $content_for_layout which is used
by ActionView's layouts

Example:

<?php $capture_helper->content_for('header'); ?>
alert('hello world');
<?php $capture_helper->end(); ?>

You can use $content_for_header anywhere in your templates.

NOTE: Beware that content_for is ignored in caches. So you shouldn't use it
for elements that are going to be fragment cached.



Generated: Mon Oct 27 12:43:49 2008 Cross-referenced by PHPXref 0.6