Views/Functions

Elgg v1.0 has a completely new views system. It is now possible to create multiple views for objects and extend existing views in order to build your Elgg out exactly how you want.

Basic view functions

  • elgg_echo(plugin:string) - Elgg echo is used to make sure all string can be translated. Find out more about internationalisation: ...
  • add_submenu_item($label, $link) - this function allows plugins to add submenu items to the plugin page. By default, these items display underneath the plugin page title. You set this in your plugin init function. Before you do, you need to check for the page context so your submenu items only display when the plugin in question is in display Here is a sample:
//add submenu options
    if (get_context() == "profile") {
	add_submenu_item(elgg_echo('profile:editdetails'), $CONFIG->wwwroot . "mod/profile/edit.php");
	add_submenu_item(elgg_echo('profile:editicon'), $CONFIG->wwwroot . "mod/profile/editicon.php");
    }
  • elgg_view_title(title, true|false) - This view will output a title at the top of every canvas area page, if there is a submenu to display, it will display by default. If you would like to over-rule this so no submenu appears, make the second param 'false'.

In Elgg is it possible to create as many canvas areas as you like. These canvas areas control the layout and display of all plugin contents. The default canvas areas that Elgg has are: one_column, two_column, widgets, groups.

To call a particular canvas area, use the follow function.

  • elgg_view_layout($type, $area1, $area2, etc etc)

$type is the canvas layout you want e.g. 'one_column' and the following variables ($area1, $area2 etc) are the content to be displayed.

Here is a sample:

// now we grab all the topics for the selected forum
$forumtopics = $forum_entity->getEntitiesFromRelationship("forum_topic");
 
// Set layout
$area1 = elgg_view("forums/viewtopics", array('forumtopics' => $forumtopics));
 
$body = elgg_view_layout("one_column", $area1);
 
// Display page
page_draw(sprintf(elgg_echo('forums:user')),$body);

Search docs