In-depth explaination of the templating system.
Posted by Konrad Piwowar, Last modified by Konrad Piwowar on 01 November 2018 02:04 PM
This article is to explain more in depth how the script is put together and how the templating system works.
First of all, the most important template is template.content_item.php. It contains the thumbnail block:
There is a similar file called template.content_item_photos.php, which is the same thing except for photo galleries.
All of the content display pages that show thumbs are put together in the same way. Examples of these pages include:
All of these pages are loading the same template files:
All of these pages are loading exactly the same template files, but the database query is being swapped out based on the URL:
The homepage is loaded in exactly the same way. On the default template with on a clean installation (or our demo site), everything above the "Free Tube" section is overall_header, the section itself is content_item repeating several times based on database query loaded from control.index_queries.php, and everything below it is overall_footer.php. On the homepage, there are additional blocks (such as Videos Being Watched) that are loaded based on "if" statements in the template files so that they only show up in the homepage. The left sidebar on /videos/ is loaded much in the same way - it's only displayed NOT on the homepage.
The media pages (so video and gallery pages) are loaded in a much simpler way:
The video page is made up of:
The gallery page is made up of:
Similarly to above, these pages are loaded via rewriterules in .htaccess
The "video" controller is loaded (so controllers/control.video.php), which grabs all the data and then loads the template files listed above. For galleries, it's the same except it loads the gallery controller as specified in the rewriterule.
Other pages, such as signup or login, are loaded similarly to the video/gallery pages as listed above. For instance, the signup page consists of:
The signup page is loaded by the signup page rewrite, so:
Index.php loads /controllers/control.signup.php (which contains all the logic of the signup process) and includes/inc.metatags.php (which determines the metatags/titles/etc for this page based on "controller=signup"), and then loads the appropriate template files.
A common question that get's asked is how to make something appear only on certain pages such as most-viewed or only on the login page if all of the pages are using the same template files. The answer to this is to use php if statements based on the information you have from the rewriterules.
For instance, if I wanted to show something in overall_header or overall_footer that appears ONLY on the signup page, I would use
If I wanted to show it only every page EXCEPT for signup, I would do the same but instead of == use != (does not equal):
We know to use $_GET['controller'] because of the rewriterule:
If you wanted to show something only on the most-viewed page, you would have to use $_GET['mode'] because the controller is the same for all the sorting pages (top rated, most viewed, newest, search results, etc), so:
If you wanted to show something only on page 1 of the most-viewed page, then you would do:
or on page 3 of top-rated:
or only on the homepage: