===== Helpers =====
These are functions that may be used in many contexts.
==== Capture ====
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 ===
begin (); ?>
[some html...]
end (); ?>
=== Add javascript to header using content_for ===
''$capture_helper->content_for("name");'' is a wrapper for Capture which will store the fragment in an instance variable similar to $content_for_layout.\\ \\
**Example:**\\
layout.tpl:\\
layout with js
{content_for_layout}
view.tpl:\\
This page shows an alert box!\\
begin ('script'); ?>
alert('hello world');
end (); ?>
Normal view text
==== distance_of_time_in_words ====
**Syntax:**\\
distance_of_time_in_words( $from_time, [ $to_time = 0], [ $include_seconds = false])\\
**Description:**\\
Reports the approximate difference in time between ''$from_time'' and ''$to_time'' in an ISO string translated to the current language:
^ Time Difference ^ Message ^
| < 20 seconds | less than x seconds* |
| < 40 seconds | less than half a minute* |
| < 60 seconds | less than a minute |
| 1 minute | 1 minute |
| < = 45 minutes | x minutes |
| < = 90 minutes | about 1 hour |
| < = 1440 minutes | about x hours |
| < = 2880 minutes | 1 day |
| > 2880 minutes | x days |
* reported only if $include_seconds = true; otherwise "less than a minute".
==== distance_of_time_in_words_to_now ====
**Syntax:**\\
distance_of_time_in_words_to_now ( $from_time, [ $include_seconds = false])\\
**Description:**\\
Reports the approximate difference in time between ''$from_time'' until now (the current time) in an ISO string translated to the current language:
^ Time Difference ^ Message ^
| < 20 seconds | less than x seconds* |
| < 40 seconds | less than half a minute* |
| < 60 seconds | less than a minute |
| 1 minute | 1 minute |
| < = 45 minutes | x minutes |
| < = 90 minutes | about 1 hour |
| < = 1440 minutes | about x hours |
| < = 2880 minutes | 1 day |
| > 2880 minutes | x days |
* reported only if $include_seconds = true; otherwise "less than a minute".
==== locale_date ====
**Syntax:**\\
locale_date( [ $iso_date ])\\
**Description:**\\
Converts an ISO date (format: yyyy-mm-dd) to the current date locale format. If ''$iso_date'' is omitted, the current date is assumed.
==== locale_date_time ====
**Syntax:**\\
locale_date_time( [ $iso_date_time = null])\\
**Description:**\\
Converts an ISO date/time (format: yyyy-mm-dd hh:mm:ss) to the current locale format. If ''$iso_date_time'' is omitted, the current date/time is assumed.
==== time_ago_in_words ====
**Syntax:**\\
time_ago_in_words ( $from_time, [ $include_seconds ])\\
**Description:**\\
Reports the approximate distance in time between ''$from_time'' and ''timestamp()'' (the current time) in an ISO string translated to the current language:
^ Time Difference ^ Message ^
| < 20 seconds | less than x seconds* |
| < 40 seconds | less than half a minute* |
| < 60 seconds | less than a minute |
| 1 minute | 1 minute |
| <= 45 minutes | x minutes |
| <= 90 minutes | about 1 hour |
| <= 1440 minutes | about x hours |
| <= 2880 minutes | 1 day |
| > 2880 minutes | x days |
* reported only if $include_seconds = true; otherwise "less than a minute".
==== _add_one ====
**Syntax:**\\
_add_one( $number)\\
**Description:**\\
Returns ''$number++'' or ''$number+1''
==== _leading_zero_on_single_digits ====
**Syntax:**\\
_leading_zero_on_single_digits( $number)\\
**Description:**\\
This returns $number > 9 ? $number : "0$number";