Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: Rudolf - tammikuu 13, 2006, 04:52:36 AP

Otsikko: Template System question
Kirjoitti: Rudolf - tammikuu 13, 2006, 04:52:36 AP
  Looking at the code I noticed that the template and language files are actually inserted before the data is being pulled out from the database and processed.

  I figured it out by now, that the templates work with the context array to show up the data.
  But how, if when those files are included the context array is empty?

  It is something that just excapes my logic. I looked at the LoadLanguage and LoadTemplate functions, but still can't understand how is possible. Some PHP trick, the way files are included?
  I would be eternally greatful if someone explains this to me.

Rudolf
Otsikko: Re: Template System question
Kirjoitti: Dannii - tammikuu 13, 2006, 07:06:43 AP
The templates are selected and loaded before the sourcefile is run, however they wait till after the source is finished to display anything. I'm not sure exactly how that is done, however it probably has something to do with the templates being evaluated instead of just run.
Otsikko: Re: Template System question
Kirjoitti: Rudolf - tammikuu 13, 2006, 10:33:31 AP
Well, this is what I said myself too.
After a little digging maybe I found the answer, though the details I still don't fully understand.
I'm almost sure that it's done using the output buffering.
Otsikko: Re: Template System question
Kirjoitti: sQuarecoW - helmikuu 11, 2006, 10:50:25 AP
I'm looking for the same thing/answers.. Is there anyone who can explain me some basics on how SMF passes all this around?
Otsikko: Re: Template System question
Kirjoitti: Dannii - helmikuu 12, 2006, 06:04:54 AP
The basics of how SMF works is that index.php finds out what action to run. It then loads the corresponding source file, which will put everything relevant into the $context array. The source file will load the corresponding template file, which will output everything it wants to from the $context array.
Otsikko: Re: Template System question
Kirjoitti: sQuarecoW - helmikuu 13, 2006, 12:43:03 IP
tnx! That's a clear and simple explanation!

But.. i've been reading through the code for some ours, nut I still can't find when de above and below template is called, and what takes care of putting it all in the right place and the right order on the screen....
Otsikko: Re: Template System question
Kirjoitti: Rudolf - helmikuu 14, 2006, 04:11:10 AP
the obExit function in the Subs.php
that's the one that actually loads the template or subtemplate
at least so it seems
It's a little bit twisted

Lainaus käyttäjältä: eldacar - helmikuu 12, 2006, 06:04:54 AP
The source file will load the corresponding template file, which will output everything it wants to from the $context array.
Actually in every source file the template files are loaded before the relevant values are put into the $context array. The template gets "loaded" in the obExit function.

The above and below templates are even more twisted. They are included in the template_header and template_footer functions in the Subs.php. These two are called within the obExit.

Rudolf