Joomla! Buffering System

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.

Joomla Component loading in buffer

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.

Module loading in joomla

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.

Template loading in joomla

If we scroll down here to the templates and take a look at the atomic template, in index.php there are placeholders for the modules as well as for the component and at this point Joomla is also going to pull in any JavaScript or CSS files that have been added during the execution of the component in the modules and it's going to add those CSS and JavaScript files right here in the jdoc: include type="head" element. And then Joomla is going to backfill all of the module content and all of the component content into these placeholders.

Jdoc head in joomla
Modules and component loading in joomla

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.

Root of joomla

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.

Index File in root of joomla