Template layers are a system used to organize and structure how web pages are displayed. They allow you to wrap content with common elements like headers, footers, and menus without needing to repeat the same code across multiple templates.
Think of a layer as a wrapper that surrounds the main content of your page. SMF uses layers to ensure that every page has a consistent look and feel.
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.