Welcome to Elgg's documentation
This is the place to find documentation on all aspects of Elgg. If you would like to contribute your own documentation please do; we want this to be a real community effort!
Newbie questions
From Elgg Documentation
[edit] Is there a definitive list of template keywords that are available in core Elgg?
gyfjyr There is a list of template keywords located here: Theme keywords
[edit] How can I find...
[edit] The current page owner ID?
The function page_owner(); should return this appropriately in the latest version of Elgg.
When creating custom pages make sure you configure the .htaccess file correctly. I.E. RewriteRule ^([A-Za-z0-9]+)\/my_custom\/?$ _custom/index.php?profile_name=$1&var1=$2
the ?profile_name (get string) must be present or page_owner does not work.
[edit] The current user ID?
$_SESSION['userid'] is your friend. This is set to -1 if the user is logged out.
And is set to 0 is the user isn't logged in - i.e. is a guest?
[edit] The current username?
$_SESSION['username'] - but check that $_SESSION['userid'] isn't -1.
[edit] The current page type (blog, files etc)?
You can find this by checking the constant 'context'.
[edit] What does includes.php actually include?
It includes all necessary files to run the system. This also includes plugins in mod/.
[edit] What's contained in $CFG and how do you use it?
$CFG will contain configuration parameters, initially set in config.php. It is a global variable, so an example usage in a function will be:
function my_function() {
global $CFG;
echo $CFG->wwwroot;
}
[edit] Where does user_info() come from and when/how can you use it?
It has been defined in lib/userlib.php and it will return the value the value of a specified (user related) field, given a user ID. E.g. user_info("username", $USER->ident) will return the user name of the currently logged in user.
[edit] How do you write code that checks the current user's permissions and ensures permissions on objects are respected?
[edit] Is there a definitive list of the contexts that are defined within Elgg and how they can be used?
Each of the top-level items have a context:
- blog
- profile
- friends
- files
- admin
- account
- network
Any plugin can also set its own context. (If you're unsure about the context a particular page is in, check its source - you'll find a call to define('context','context-name'); towards the top.)
These can be accessed through the 'context' constant, and used to alter the way menus display, things are added to the sidebar, etc, in the module_init and module_pagesetup functions.
[edit] What classes / functionality does Elgg implement to handle the database? How do I use them?
All database related code lives in lib/datalib.php. This is a wrapper around AdoDB. datalib.php is well documented, you'll find example usage in the code.
[edit] How do the templates_draw and templates_page_draw functions work
- templates_page_setup() sets up the templating system
- templates_draw() wraps the body (your content) in the standard content holder
- templates_page_draw() returns the rendered page, use an echo statement to send it to the user's browser
Back to Development frontpage

