m (No capitals in the middle of a sentence) |
No edit summary |
||
Line 1: | Line 1: | ||
Context is basically, well, the context of this page view. In other words, it's what makes one view different from the next or last. Maybe there are more or less boards... maybe someone posted a new topic... these are all things the template context can tell you. The same context information isn't available everywhere. For example, the list of boards you can move a [[Topic|topic]] to isn't there when you are editing your [[Profile|profile]] because that's illogical. | Context is basically, well, the context of this page view. In other words, it's what makes one view different from the next or last. Maybe there are more or less boards... maybe someone posted a new topic... these are all things the template context can tell you. The same context information isn't available everywhere. For example, the list of boards you can move a [[Topic|topic]] to isn't there when you are editing your [[Profile|profile]] because that's illogical. | ||
== Using $context == | |||
$context is used when you want to store data to be displayed in a template, or when you need to carry data from one function to another (though [http://php.net/manual/en/functions.arguments.php parameters] should be used where possible instead). | |||
Before using $context, you need to add it as a global to your function. | |||
== Examples == | |||
<code>function addOne() | |||
{ | |||
// Before we can use $context, we need to global it. | |||
global $context; | |||
// Check if the key already exists in $context. If it does not, create it. | |||
if (empty($context['number'])) | |||
$context['number'] = 0; | |||
// Then add one to the key in $context. | |||
++$context['number']; | |||
}</code> | |||
[[Category:FAQ]] | [[Category:FAQ]] |
Latest revision as of 15:56, 22 May 2013
Context is basically, well, the context of this page view. In other words, it's what makes one view different from the next or last. Maybe there are more or less boards... maybe someone posted a new topic... these are all things the template context can tell you. The same context information isn't available everywhere. For example, the list of boards you can move a topic to isn't there when you are editing your profile because that's illogical.
Using $context
$context is used when you want to store data to be displayed in a template, or when you need to carry data from one function to another (though parameters should be used where possible instead).
Before using $context, you need to add it as a global to your function.
Examples
function addOne()
{
// Before we can use $context, we need to global it.
global $context;
// Check if the key already exists in $context. If it does not, create it.
if (empty($context['number']))
$context['number'] = 0;
// Then add one to the key in $context.
++$context['number'];
}