Context - What is $context

From Online Manual

Jump to: navigation, search

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']; }