Usable variables

Because we want this template system to be practical for us, and because we don't want to always be assigning all the common variables we'll need rightat the end of our scripts, Chamilo comes with a set of pre-defined variables and arrays you can use.

Here is a list of those variables and arrays... Not that it might not be exhaustive and that, at this time, we have no way of helping you list these, but you could hack into main/inc/lib/template.lib.php and search for all $this->assign('literal', $variable) ; calls to find out.

The _u array

The _u array contains general information about the user. You could get the user's firstname to be printed inside any tpl by using the following syntax :

{{ _u.firstname }}

Here is a complete list of the values it contains, together with an example of the value you'll get from them. As you will see, some of these are duplicated under a slightly different name. We recommend always using the lowercase variables, as others should be cleaned out progressively in the future.

[complete_name] => John Doe
[complete_name_with_username] => John Doe (admin)
[firstname] => John 
[lastname] => Doe 
[firstName] => John 
[lastName] => Doe 
[mail] => [email protected]
[email] => [email protected]
[picture_uri] => 
[user_id] => 1 
[official_code] => ADMIN 
[status] => 1 
[auth_source] => platform
[active] => 1 
[username] => admin 
[theme] => 
[language] => english 
[last_login] => 2014-01-11 15:21:57
[lastLogin] => 2014-01-11 15:21:57
[avatar] => http://my.chamilo110.net/main/img/unknown.jpg
[avatar_sys_path] => /var/www/chamilo-lms/main/img/unknown.jpg
[avatar_small] => http://my.chamilo110.net/main/img/unknown_22.jpg
[logged] => 1 
[is_admin] => 1 
[messages_count] => 0
[messages_invitations_count] => 0

The _p array

This array contains a list of different forms of paths that you might need at the template level, for example to link to other resources.

You could get the basis of the courses directory to be printed inside any tpl by using the following syntax :

Note that system paths, although easily available otherwise in the PHP scripts, are not provided here, as they should never be shown to the final users (even in the HTML source code).

The _s array

This array contains some system variables representing general platform information

i.e. you can get the site name (as configured in the global settings) to be printed inside any tpl by using the following syntax :

The _c array

This array (only present starting from 1.9.8) contains information about the current course.

You can check if the current course is defined (i.e. if the user is inside a course right now) by using the course_is_set variable :

The _c array looks like this :

As you can see, it also contains the session ID. Session ID is always 0 when we are not in a session at all.

You can also use, from the tpl, the {{ course_code }} variable, which is equivalent to {{ _c.code }}.

Although a bit more complex already, you could decide whether or not you'd want to show a link to a course by checking its visibility, like so:

As you can see, we combined several variables here, including one from the _s array, to write a condition that will show a full link to the course homepage to the user, only if the course has a visibility of « 1 ».

Individual variables

Other variables are defined individually but are always available inside any template.

As for the previous groups, the list below should be self-explanatory through the example values provided. In some cases, we add a comment after a « // » sign to give you more info.

i.e. you can get the name of the current CSS in use (and so get elements from the images/ folder in there) simply by using the following syntax:

Last updated