In very simple PHP applications, many people will choose to execute their code in the order the results appear on the screen. On the other hand Joomla runs each module and components separately, then assembles everything into the template.
Let's take a look at some of the output that Joomla is generating and how it gets all assembled together.
This is the root folder of our fresh copy of Joomla and first Joomla is going to execute a component. The most common component that's used in Joomla is the content component. So if we go down here to the views folder, this is where all the output from the content component is going to be generated. If we were viewing a single article, there is a default.php file under the tmpl folder and that's where the markup for the article is going to be output. So as Joomla runs the component it's going to load this default.php file and it's just going to grab all of the output from this file as Joomla parses through it.
Now its not going to display it right away, it's going to hold it in a PHP output buffer and then save it until it's ready to display. So after Joomla is done running the component, next it's going to run the module.
So we are going to have the login module on most of our pages and just like the component the mod_login folder has a tmpl folder and inside that tmpl folder is another default.php file. This default.php file has all of the markup that's necessary to generate the login module. And again Joomla is going to run this module, it's going to gather up all the output that this file is generating and it's going to save it until it's ready to display it.
So finally Joomla loads the template.
Then finally once it's assembled all of the content in the template, it still hasn't sent it to the browser yet. After the template has all of the content assembled inside of it, Joomla is going to output everything here at the bottom of index.php.
So none of the output goes to the browser before everything has been assembled. Joomla assembles all of the pieces together, and then it finally echoes everything out at the end, and then you'll notice that there's an on afterRender event here. Once Joomla has all of the content in place you have one last chance where you can go and modify that output. Joomla's output buffering makes it possible to handle output in incremental pieces and if all else fails you always have one last chance to modify the output before it goes to the browser.