page-structure.rst 2.3 KB

  1. Page structure best practice
  2. ============================
  3. Elgg pages have an overall pageshell and a main content area. In Elgg 1.0+, we've marked out a space \"the canvas\" for items to write to the page. This means the user always has a very consistent experience, while giving maximum flexibility to plugin authors for laying out their functionality.
  4. Think of the canvas area as a big rectangle that you can do what you like in. We've created a couple of standard canvases for you:
  5. - one column
  6. - two column
  7. - content
  8. - widgets
  9. are the main ones. You can access these with the function:
  10. .. code:: php
  11. $canvas_area = elgg_view_layout($canvas_name, array(
  12. 'content' => $content,
  13. 'section' => $section
  14. ));
  15. The content sections are passed as an ``array`` in the second parameter. The array keys correspond to sections in the layout, the choice of layout will determine which sections to pass. The array values contain the html that should be displayed in those areas. Examples of two common layouts:
  16. .. code:: php
  17. $canvas_area = elgg_view_layout('one_column', array(
  18. 'content' => $content
  19. ));
  20. .. code:: php
  21. $canvas_area = elgg_view_layout('one_sidebar', array(
  22. 'content' => $content,
  23. 'sidebar' => $sidebar
  24. ));
  25. You can then, ultimately, pass this into the ``elgg_view_page`` function:
  26. .. code:: php
  27. echo elgg_view_page($title, $canvas_area);
  28. You may also have noticed that we've started including a standard title area at the top of each plugin page (or at least, most plugin pages). This is created using the following wrapper function, and should usually be included at the top of the plugin content:
  29. .. code:: php
  30. $start_of_plugin_content = elgg_view_title($title_text);
  31. This will also display any submenu items that exist (unless you set the second, optional parameter to false). So how do you add submenu items?
  32. In your plugin_init function, include the following call:
  33. .. code:: php
  34. if (elgg_get_context() == "your_plugin") {
  35. // add a site navigation item
  36. $item = new ElggMenuItem('identifier', elgg_echo('your_plugin:link'), $url);
  37. elgg_register_menu_item('page', $item);
  38. }
  39. The submenu will then automatically display when your page is rendered. The 'identifier' is a machine name for the link, it should be unique per menu.