Note: You are currently viewing documentation for Moodle 3.7. Up-to-date documentation for the latest stable version of Moodle may be available here: How Moodle outputs HTML.

Obsolete:How Moodle outputs HTML: Difference between revisions

From MoodleDocs
(Shifted to dev docs)
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Moodle 2.0}}
#REDIRECT [[:dev:How Moodle outputs HTML]]
 
If you think about the HTML that is output by Moodle, then you can split it into two parts:
# the parts like the header and the user-interface, that are generated automatically by the Moodle code and the themes; and
# the bits like the contents of forum posts and labels that are input by the users.
This page is about the bits of output that are generated automatically. It explains how that happens.
 
{{Work_in_progress}}
 
 
==History==
 
Most of what is described here is new in Moodle 2.0. The work that lead to this new system is described in [[Development:Theme engines for Moodle?]] and [[Development:Navigation 2.0 implementation plan]]. Those documents were both written before the new system was developed and shows how the thinking evolved and the rationale behind it.
 
If you are familiar with Moodle 1.9 or before, and just wish to update your existing code, you may wish to read [[Development:Migrating your code to the 2.0 rendering API]].
 
==Overview==
 
I said above that this page was about the parts of the output that were automatically generated by Moodle code. We can break those bits of output down further:
# The overall layout of the page including the header and the footer. This is generated from the layout template provided by the theme (for example theme/standard/layout.php).
# The blocks that can appear in various places on the page. Where the blocks can appear on the page is determined by the theme layout. Which blocks appear where on which pages is configured by the user. The code that manages this is in blocklib.php. Finally, the contents of the blocks is a mixture of user-entered content and automatically generated content.
# The main content in the middle of the page. This is generated by the particular script, for example mod/forum/view.php using the output libraries. (Moodle mostly uses a transaction script architecture.)
 
 
==Basic HTML output and $OUTPUT==
 
 
 
==Themes==
 
Themes (along with some of the other the configuration choices made by the administrator) control the overall look of a Moodle site.
 
A Moodle theme is a folder of code like theme/mytheme. It contains a number of files:
; config.php
: tells Moodle the settings that this theme wants.
; layout.php, layout-head.php, ...
: defines the overall layout of the page. Different types of page can have different templates. This is controlled by config.php.
; styles.css, styles_colours.css, ...
: the stylesheets that determine the layout. It is up to the theme whether to have one or many.
; rtl.css
: A special stylesheet that is only included if the current language is right-to-left.
; readme.html, screenshot.jpg
: Information about the theme. Used in the theme chooser user interface.
; favicon.ico, pix/*
: Images that the theme wants to use. These can replace the default Moodle icons.
; meta.php
: A way to add information to the page header. Somewhat an implementation detail.
; styles.php
: Implementation detail. Responsible for serving the CSS.
 
===Theme config.php===
 
===Layout templates===
 
===Ways themes can change other parts of the HTML===
 
====Basic themes====
 
====Minor changes to the HTML====
 
====Templated themes====
(Experimental)
 
$THEME gets initialised the frist time you use $OUTPUT, or the first time you refer to $PAGE->theme
 
 
==Blocks==
 
 
 
==Plugin-specific output==
 
$OUTPUT lets themes customise the HTML used for standard things like boxes, but what about places where code echoes HTML directly? Well, in addition to moodle_core_renderer, every plugin should also define its own renderer, like moodle_mod_workshop_renderer, and all  module-specific HTML output should done in methods of that class. That class should be defined in a files called renderers.php inside your plugin.
 
When you actually want to do some output, you need to get an instance of your class (or whatever subclass the theme wants to substitute). You do that like this:
<code php>
global $PAGE; // If necessary.
$wsoutput = $PAGE->theme->get_renderer('mod_workshop', $PAGE);
echo $wsoutput->manual_allocation_interface($workshop, $allocationdata);
</code>
The moodle_mod_workshop_renderer object will have access to a moodle_core_renderer available as $this->output. You should use this instead of global $OUTPUT, and you should use it. That is, boxes in the workshop should look like boxes elsewhere, so boxes in the workshop should be output with $this->output->box().
 
 
==How to learn more==
 
Software normally needs documentation on three levels:
# An general overview of how all the parts fit together. You've just read that!
# Detailed documentation of the API and how to use it. What functions exist. What arguments they take and what they mean. What is returned. You can find that at http://phpdocs.moodle.org/. All the output code is in the moodlecore package.
# All the details of how the code actually works. In the open source world, the best way to learn that (after you have read the overview) is to read the code itself. It is the only sort of documentation that never goes out of date!
 
You should also remember Moodle's [[Pedagogy|social constructionist pedagogy]]. We learn best by doing, and then showing what we have done to others; we learn by looking at what other people have done; and we learn by asking each other questions. Don't be afraid to use the [http://moodle.org/course/view.php?id=5 forums] to share what you have done, and to ask for further explanation. This document has already benefited greatly from the questions that Sam Hemelryk and David Mudrak asked when they started working with this code.
 
 
==See also==
 
* [[Development:Migrating your code to the 2.0 rendering API]]
* [[Development:Theme_engines_for_Moodle%3F]]
* [[Development:Navigation_2.0_implementation_plan]]
* [[Development:Navigation_2.0]]
 
{{CategoryDeveloper}}

Latest revision as of 08:48, 27 July 2011