Template Layers From Online Manual

Jump to: navigation, search

Template layers are pairs of sub-templates that wrap around the main content or other layers, much like layers of an onion. Each layer consists of two parts: an "above" sub-template and a "below" sub-template.

These layers are displayed around the core content, allowing you to add elements like headers, sidebars, or footers without modifying the core template directly.

Adding or Modifying Layers

SMF allows you to customize layers. For instance, you can:

  • Add a custom header or sidebar by inserting a new layer.
  • Remove or replace default layers for specific pages.

Layers are managed through the $context['template_layers'] array. For example:

$context['template_layers'] = ['html', 'body', 'main'];
$context['sub_template'] = 'sub';

This definition will call the following functions in order:

Top layers
template_html_above
template_body_above
template_main_above
Sub-template
template_sub
Bottom layers
template_main_below
template_body_below
template_html_below

Why Use Template Layers?

  • Reusability: Common elements (like headers) don’t need to be rewritten for every template.
  • Consistency: Ensures all pages share a uniform structure.
  • Customization: Makes it easy to modify specific parts of the layout without altering the core content.

By using template layers, SMF simplifies web page design while maintaining flexibility for customization.



Advertisement: