Template Variables
Mon Feb 21 08:01 System-generated article

Introduction  

This page lists all the variables available to action templates, component templates and template partials in The Bug Genie.

Any action variables  

Any variables that have been assigned in the action will be passed on to the template when the action is completed.

Examples: actions.class.php runIndex() action:
public function runIndex(TBGRequest $request)
{
	$this->my_variable = 'fu';
}


mymodule/templates/index.php
<?php echo $my_variable; // echoes "fu" ?>


$tbg_request  

In the template you can always access data from the request, via the $tbg_request variable. This is the same object you get when you do TBGContext::getRequest().

Example: mymodule/templates/index.php
<?php echo ($tbg_request->isMethod(TBGRequest::POST)) ? 'yes' : 'no'; // echoes "yes" if this was a post request, or "no" if it wasn't ?>


$tbg_response  

The template has access to the response object, which will be useful if you want to add javascript files, headers, feeds etc from your template. The response is also where you set the page title. $tbg_response is an instance of TBGResponse.

Example: mymodule/templates/index.php
<?php
	$tbg_response->setTitle('Frontpage');
	$tbg_response->addJavascript('scrum.js');
?>


$tbg_routing  

You can access the routing object from the template via $tbg_routing, which is an instance of the TBGRouting object, elsewhere accessed via TBGContext::getRouting(). This object can be used if you want to find out what specific action was run, what template was being included, etc.

Example: mymodule/templates/index.php
<?php echo $tbg_routing->getCurrentRouteModule(); // echoes "mymodule" ?>


$tbg_user  

This is the instantiated user object, which may or may not be logged in, depending on the security settings.

Example:
<?php echo ($tbg_user->isAuthenticated()) ? 'logged in' : 'not logged in'; ?>


Attachments 0

Comments 0

/unthemed/mono/no-comments.png
Expand, collaborate and share
Post a comment and get things done