Sub templates From Online Manual

Revision as of 02:51, 13 June 2010 by Jake (talk | contribs)
Jump to: navigation, search

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.

Code: // Show an error message... function template_fatal_error() {

  global $context, $settings, $options, $txt;
  echo '
', $context['error_title'], '
        ', $context['error_message'], '

';

  // Show a back button (using javascript.)
  echo '

<a href="javascript:history.go(-1)">', $txt[250], '</a>

';

}

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 '

', $context['error_title'], '
        ', $context['error_message'], '

';

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 '

<a href="javascript:history.go(-1)">', $txt[250], '</a>

';

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



Advertisement: