Class CaptureHelper

(line 60)

Description


Located in File: /AkActionView/helpers/capture_helper.php

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



Class Variables

Summary:
mixed $_stack

$_stack = array() (line 62)

Data type : mixed

Class Constants

Summary:

Method Detail

Summary:
void begin ([ $var_name = ''])
void content_for ( $name)
void end ([ $add_to_view = true])
void _addVarToView ( $var_name,  $content)

Method begin (line 74)

void begin( [ $var_name = ''])

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(); ?>

Parameters

  • $var_name:

Info

Method content_for (line 115)

void content_for( $name)

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.

Parameters

  • $name:

Info

Method end (line 80)

void end( [ $add_to_view = true])

Parameters

  • $add_to_view:

Info

Method _addVarToView (line 90)

void _addVarToView( $var_name, $content)

Parameters

  • $var_name:
  • $content:

Info

Inherited Variables

Inherited Class Variable Summary

Inherited Methods

Inherited Method Summary


Documentation generated on Sat, 20 Oct 2007 00:23:03 +0200 by phpDocumentor 1.3.2