Page Rendering Process
Overview of how TWiki works
To achieve a goal in TWiki either by making use of existing features or implementing new features, good understanding of how TWiki works is crucial.
That said, this topic explains how TWiki processes various TWiki operations - view, edit, save, attach, upload, etc.
Here's the basic steps of the page rendering by TWiki.
- Preferences variables are read. TWikiVariables#PreferencesVariables describes what exactly happens in this step. This step is taken regardless of script (view, edit, etc.) while the steps below may not happen. For example, the save script saves the topic text and then redirects to the corresponding view URL hence the script doesn't take the following steps
- The page template for the script is read and expanded. TWikiTemplates explains this step
- TWiki variables in the template are expanded. A view and edit templates have
%TEXT%, which is expanded to the raw text of the page
- TWiki markup is converted into HTML
Preferences variables are read
Preferences variables are defined at an early stage of TWiki processing.
After this step, no preferences variables are set.
Please note that topics INCLUDE'd by the current topic are not read for preferences variables.
in an INCLUDE'd topic take effect since
are variables expanded in a later stage.
" * Set VARIABLE = VALUE"
in an INCLUDE'd topic doesn't have a chance to be read.
Template is read and expanded
As mentioned above, TWikiTemplates
describes how a template is selected and read.
It's worth mentioning that template expansion happens before variable expansion.
At the end of step, all template directives are resolved,
hence there aren't any
Variables may be nested - a variable may be a parameter of another variable and there is no limitation of nesting level.
If variables are nested, they are processed from the inner-most to the outer-most.
A topic may have any number of variables. Variables at the same nesting level are processed from top to bottom.
You can see it from the example below.
TWiki markup to HTML
At this point, all variables are expanded.
Markup described on TextFormattingRules
are converted into HTML
You may want to suppress this step to see the result of variable expansion not converted into HTML.
You can do that by supplying raw=expandvariables URL parameter to a view URL:
So far, how plugins are involved with page rendering hasn't been discused. Here's how.
In many cases, plugins introduce predefined variables such as
Those don't make structural difference to how a TWiki topic is written.
Those variables are introduced by calling e.g.
in the plugin code file.
Some plugins extend TWiki markup.
For example, the table notation in TWiki (an example shown below) is provided by the TablePlugin
. Though the table notation is regarded as an integral part of TWiki markup, it is implemented by a plugin rather than the TWiki core.
| One One | One Two | One Three |
| ^ | Two Two | Two Three |
| Three One | ^ | Three Three |
There are various places in the TWiki core where functions provided by plugins are called.
For example, TablePlugin
has a function named
It's called before the TWiki markup to HTML conversion takes place.
As you can imagine, if a plugin has
defined, it's called after the core TWiki markup to HTML processing.
A plugin may have
defined, which is called immediately after normal TWiki variables are expanded.
may yield TWiki variables, normal TWiki variable expansion is conducted again after that.
defined to process
. You may think
can be implemented simply by
but it cannot be since
needs to look outside its parameters to do things such as
In addition to
, there are other functions called from TWiki core as well.
You can see the complete list of such functions on EmptyPlugin.pm in the EmptyPlugin.
Related Topics: DeveloperDocumentationCategory