Sub templates: Difference between revisions From Online Manual

Jump to: navigation, search
mNo edit summary
m (template:code)
Line 3: Line 3:
It's important to note that sub-templates are grouped within templates. The error sub-template "template_fatal_error()" can be found in the Errors.template.php, just as shown below.
It's important to note that sub-templates are grouped within templates. The error sub-template "template_fatal_error()" can be found in the Errors.template.php, just as shown below.


''Code:
{{code|1=<nowiki>// Show an error message...
<pre>// Show an error message...
function template_fatal_error()
function template_fatal_error()
{
{
Line 27: Line 26:
<a href="javascript:history.go(-1)">', $txt[250], '</a>
<a href="javascript:history.go(-1)">', $txt[250], '</a>
</div>';
</div>';
}</pre>
}
</nowiki>}}


'''Breaking it down:'''
'''Breaking it down:'''


Code:
Code:
<pre>// Show an error message...</pre>
{{code|1=// Show an error message...}}


This is used for comments to guide and tell the admin what the following block of code is.
This is used for comments to guide and tell the admin what the following block of code is.


Code:
Code:
<pre>function template_fatal_error()
{{code|1=function template_fatal_error()
{
{
…
 
}</pre>
}
}}


In JavaScript, this is the sub-template that will be executed upon encountering an error.
In JavaScript, this is the sub-template that will be executed upon encountering an error.


Code:
Code:
<pre>global $context, $settings, $options, $txt;</pre>
{{code|1=global $context, $settings, $options, $txt;}}


This is a PHP declaration of some variables.
This is a PHP declaration of some variables.


Code:
Code:
<pre>echo '
{{code|1=<nowiki>echo '
<table border="0" width="80%" cellspacing="0" align="center"
<table border="0" width="80%" cellspacing="0" align="center"
cellpadding="4" class="tborder">
cellpadding="4" class="tborder">
Line 61: Line 62:
       </td>
       </td>
   </tr>
   </tr>
</table>';</pre>
</table>';</nowiki>}}


This is the actual HTML that will be sent to the browser. Note the use of the previously declared variable, $context.
This is the actual HTML that will be sent to the browser. Note the use of the previously declared variable, $context.
Line 67: Line 68:
Code:
Code:


<pre>// Show a back button (using JavaScript.)</pre>
{{code|1=// Show a back button (using JavaScript.)}}


This is another comment.
This is another comment.


Code:
Code:
<pre>   echo '
{{code|1=&nbsp;  <nowiki>echo '
<div align="center" style="margin-top: 2ex;">
<div align="center" style="margin-top: 2ex;">
<a href="javascript:history.go(-1)">', $txt[250], '</a>
<a href="javascript:history.go(-1)">', $txt[250], '</a>
</div>';</pre>
</div>';</nowiki>}}


This is some more HTML code that will be sent to the browser.
This is some more HTML code that will be sent to the browser.

Revision as of 08:00, 12 April 2011

A sub-template is what the HTML is in. For example, admins can change the admin_login sub-template to make the administrative password prompt look different. They could change the error sub-template to change what is displayed upon an error.

It's important to note that sub-templates are grouped within templates. The error sub-template "template_fatal_error()" can be found in the Errors.template.php, just as shown below.

// Show an error message...
function template_fatal_error()
{
   global $context, $settings, $options, $txt;

   echo '
<table border="0" width="80%" cellspacing="0" align="center"
cellpadding="4" class="tborder">
   <tr class="titlebg">
      <td>', $context['error_title'], '</td>
   </tr>
   <tr class="windowbg">
      <td style="padding-top: 3ex; padding-bottom: 3ex;">
         ', $context['error_message'], '
      </td>
   </tr>
</table>';

   // Show a back button (using javascript.)
   echo '
<div align="center" style="margin-top: 2ex;">
<a href="javascript:history.go(-1)">', $txt[250], '</a>
</div>';
}

Breaking it down:

Code:

// Show an error message...

This is used for comments to guide and tell the admin what the following block of code is.

Code:

function template_fatal_error()
{

}

In JavaScript, this is the sub-template that will be executed upon encountering an error.

Code:

global $context, $settings, $options, $txt;

This is a PHP declaration of some variables.

Code:

echo '
<table border="0" width="80%" cellspacing="0" align="center"
cellpadding="4" class="tborder">
   <tr class="titlebg">
      <td>', $context['error_title'], '</td>
   </tr>
   <tr class="windowbg">
      <td style="padding-top: 3ex; padding-bottom: 3ex;">
         ', $context['error_message'], '
      </td>
   </tr>
</table>';

This is the actual HTML that will be sent to the browser. Note the use of the previously declared variable, $context.

Code:

// Show a back button (using JavaScript.)

This is another comment.

Code:

    echo '
<div align="center" style="margin-top: 2ex;">
<a href="javascript:history.go(-1)">', $txt[250], '</a>
</div>';

This is some more HTML code that will be sent to the browser.



Advertisement: