Difference between revisions of "Sub templates"

From Online Manual

Jump to: navigation, search
m (2 revisions: Importing from local.)
Line 1: Line 1:
I'm glad you asked. A sub template is what actually has the html in it. You can change, for example, the admin_login sub template to make the administrative password prompt look different. You could change the error sub template to change what is displayed upon an error.
+
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.
+
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.
  
<div class="codeheader">: <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation"></a></div><code>// Show an error message...
+
''Code:
 +
// Show an error message...
 
function template_fatal_error()
 
function template_fatal_error()
 
{
 
{
&nbsp;&nbsp;&nbsp;global $context, $settings, $options, $txt;
+
  global $context, $settings, $options, $txt;
  
&nbsp;&nbsp;&nbsp;echo &#039;
+
  echo '
&lt;table border=&quot;0&quot; width=&quot;80%&quot; cellspacing=&quot;0&quot; align=&quot;center&quot;
+
<table border="0" width="80%" cellspacing="0" align="center"
cellpadding=&quot;4&quot; class=&quot;tborder&quot;&gt;
+
cellpadding="4" class="tborder">
&nbsp;&nbsp;&nbsp;&lt;tr class=&quot;titlebg&quot;&gt;
+
  <tr class="titlebg">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;&#039;, $context&#91;&#039;error_title&#039;], &#039;&lt;/td&gt;
+
      <td>', $context['error_title'], '</td>
&nbsp;&nbsp;&nbsp;&lt;/tr&gt;
+
  </tr>
&nbsp;&nbsp;&nbsp;&lt;tr class=&quot;windowbg&quot;&gt;
+
  <tr class="windowbg">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td style=&quot;padding-top: 3ex; padding-bottom: 3ex;&quot;&gt;
+
      <td style="padding-top: 3ex; padding-bottom: 3ex;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#039;, $context&#91;&#039;error_message&#039;], &#039;
+
        ', $context['error_message'], '
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/td&gt;
+
      </td>
&nbsp;&nbsp;&nbsp;&lt;/tr&gt;
+
  </tr>
&lt;/table&gt;&#039;;
+
</table>';
  
&nbsp;&nbsp;&nbsp;// Show a back button (using javascript.)
+
  // Show a back button (using javascript.)
&nbsp;&nbsp;&nbsp;echo &#039;
+
  echo '
&lt;div align=&quot;center&quot; style=&quot;margin-top: 2ex;&quot;&gt;
+
<div align="center" style="margin-top: 2ex;">
&lt;a href=&quot;javascript:history.go(-1)&quot;&gt;&#039;, $txt[250], &#039;&lt;/a&gt;
+
<a href="javascript:history.go(-1)">', $txt[250], '</a>
&lt;/div&gt;&#039;;
+
</div>';
}</code>
+
}''
Breaking it a part:
 
  
<div class="codeheader">: <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation"></a></div><code>// Show an error message...</code>
+
'''Breaking it down:'''
Is used for comments to guide and tell you what the following block of code is.
 
  
<div class="codeheader">: <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation"></a></div><code>function template_fatal_error()
+
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()
 
{
 
{
+
…
}</code>
+
}''
This is the sub template that will be executed upon an 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.
  
<div class="codeheader">: <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation"></a></div><code>global $context, $settings, $options, $txt;</code>
+
Code:
This is a php declaration of some variables.
 
  
<div class="codeheader">: <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation"></a></div><code>echo &#039;
+
''// Show a back button (using JavaScript.)''
&lt;table border=&quot;0&quot; width=&quot;80%&quot; cellspacing=&quot;0&quot; align=&quot;center&quot;
 
cellpadding=&quot;4&quot; class=&quot;tborder&quot;&gt;
 
&nbsp;&nbsp;&nbsp;&lt;tr class=&quot;titlebg&quot;&gt;
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;&#039;, $context&#91;&#039;error_title&#039;], &#039;&lt;/td&gt;
 
&nbsp;&nbsp;&nbsp;&lt;/tr&gt;
 
&nbsp;&nbsp;&nbsp;&lt;tr class=&quot;windowbg&quot;&gt;
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td style=&quot;padding-top: 3ex; padding-bottom: 3ex;&quot;&gt;
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#039;, $context&#91;&#039;error_message&#039;], &#039;
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/td&gt;
 
&nbsp;&nbsp;&nbsp;&lt;/tr&gt;
 
&lt;/table&gt;&#039;;
 
</code>This is the actual HTML that will be shown (echo) to the browser. Note the use of $context there.
 
  
<div class="codeheader">: <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation"></a></div><code>// Show a back button (using javascript.)</code>
+
This is another comment.
Another comment.
 
  
<div class="codeheader">: <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation"></a></div><code>&nbsp;&nbsp;&nbsp;echo &#039;
+
Code:
&lt;div align=&quot;center&quot; style=&quot;margin-top: 2ex;&quot;&gt;
+
  ''echo '
&lt;a href=&quot;javascript:history.go(-1)&quot;&gt;&#039;, $txt[250], &#039;&lt;/a&gt;
+
<div align="center" style="margin-top: 2ex;">
&lt;/div&gt;&#039;;</code>
+
<a href="javascript:history.go(-1)">', $txt[250], '</a>
Another block of HTML.
+
</div>';''
  
'''Next:''' [[http://docs.simplemachines.org/index.php?topic=226|" class="bbc_link">Where do I find the templates and sub templates?]]
+
This is some more HTML code that will be sent to the browser.

Revision as of 21:51, 12 June 2010

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.