A WebBox is a template which has also some PHP code associated with it. It is a self-contained and independent template which can be easily included in other pages or in other applications. In fact, it may also have some JavaScript code, CSS stylesheets, SQL queries etc., associated with it.
It is denoted by the tag <WebBox> and it has an ID attribute:
<WebBox ID="box_id"> <!-- content of WebBox --> </WebBox>
The identifier must be different for each WebBox used in the application.
The PHP code (as well as JS code, CSS styles etc.) are associated to the WebBox by means of box_id, the identifier of the WebBox. When the framework parses a <WebBox> tag, it looks for a file named box_id.php in the same folder where the WebBox template is. If it finds such a file, it includes it.
The box_id.php file must contain the definition of a PHP class that extends the class WebObject, like this:
<?php class box_id extends WebObject { . . . } ?>
The class WebObject is defined by the framework. Among other things, it also contains the member function WebObject::onRender().
The function onRender() of the class WebObject is called by the framework at the time of the HTML page construction (the page that is sent to the browser), just before the template of the WebBox is outputed (rendered). Actually WebObject::onRender() is an abstract (empty) function, and the framework expects the class box_id to override it, in order to do something useful for the WebBox.What is usually done in box_id::onRender() is assigning values to the variables used in the template of the WebBox box_id, so that the template is rendered properly. These values are assigned by the function WebApp::addVar("var_name", "var_value").
Besides the file that contains the template of the WebBox and the box_id.php that contains its PHP class, there may be other files as well that belong to the WebBox. These are: box_id.js that contains the JavaScript code of the WebBox, box_id.css that contains the stylesheet of the WebBox, etc.. If the framework finds such files, it automatically integrates them in the generated HTML page. For example, it includes box_id.js and box_id.css in the <head> of the page. If you view the HTML code of this page, you may notice in the <head> these lines that have been added automatically by the framework for the WebBox menu:
<script language='JavaScript' src='/app3/templates/menu/menu.js'></script> <link rel='stylesheet' href='/app3/templates/menu/menu.css' type='text/css'>
From the files of a WebBox, the template is the most important. There can be a WebBox without JS code or without PHP code, but there cannot be a WebBox without TPL(template) code.
A WebBox is defined inside a template file and the TPL code of the WebBox is inside the <WebBox> tag (is the content of the <WebBox> element). However a WebBox is different from a template because it can also have its own PHP code. Another difference is that a template must include explicitly the JS code and the CSS code (if it has its own), however, for a WebBox the framework handles them automatically, by including them at the <head> of the page