-
Notifications
You must be signed in to change notification settings - Fork 2
Templates
S2 templates contain the HTML markup for page layouts. All content added through the control panel is stored in a database. When generating pages, the required data is retrieved from the database and inserted into the template.
Technically, templates are regular PHP files.
While they primarily contain markup, they can also include executable PHP code.
Templates are included within the local scope of a method, so global variables must be accessed using $GLOBALS.
Important notes:
- Including large code blocks in templates is not recommended
- For extending functionality, use the dedicated extensions mechanism
- Template files must be saved in UTF-8 encoding without BOM (Byte Order Mark) to ensure proper display of non-English characters
The S2 core provides these default templates in the _include/templates/ directory:
- site.php – Standard page template
- back_forward.php – Minimal layout without sidebar (used in zeta style)
- mainpage.php – Homepage template
- service.php – System pages (e.g. comment previews)
- error404.php – 404 Error page template
S2 uses this template lookup order:
- Current style’s directory
- Core
_include/templates/directory
This allows styles to override default templates.
Best practices:
- Create custom styles instead of modifying core templates
- Core template modifications may cause conflicts during S2 updates
- Always maintain UTF-8 encoding (without BOM) in template files
For convenience when creating additional navigation panels, all links in templates undergo special processing.
When the href attribute value matches the current page’s URL, the a element is replaced with a span element.
When the current page’s URL starts with the href attribute value, the current class is added to the a element.
For this replacement to occur, links must use absolute paths (without the domain).
Additionally, the opening a tag should not have other attributes, and whitespace should be minimal.
For example, the following link will be processed: <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2F">...</a>.
Let’s examine the _include/templates/site.php template. Special placeholders in the form of HTML comments mark the locations where the HTML code of page fragments will be inserted.
<?php if (!isset($this)) die; ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title><!-- s2_head_title --></title>
<!-- s2_meta -->
<!-- s2_styles -->
<!-- s2_navigation_link -->
<!-- s2_rss_link -->
</head>
<body class="site">
<div id="crumbs"><!-- s2_crumbs --></div>
<!-- s2_search_field -->
<div id="header"><!-- s2_site_title --></div>
<div id="container">
<div id="content">
<!-- s2_author -->
<!-- s2_title -->
<!-- s2_date -->
<!-- s2_text -->
<!-- s2_subarticles -->
<!-- s2_tags -->
<!-- s2_recommendations -->
<!-- s2_comments -->
<!-- s2_comment_form -->
</div>
<div id="menu">
<!-- s2_menu_siblings -->
<!-- s2_menu_children -->
<!-- s2_menu_subsections -->
<!-- s2_article_tags -->
<!-- s2_blog_tags -->
</div>
</div>
<!-- s2_debug -->
<div id="footer">
<p id="copyright"><!-- s2_copyright --></p>
<p id="queries"><!-- s2_querytime --></p>
</div>
<!-- s2_scripts -->
</body>
</html>Below are descriptions of all placeholders supported by the S2 engine. Note that extensions can define any additional placeholders. Extension placeholders are not described here.
These placeholders correspond to the fields in the control panel editor.
-
<!-- s2_title -->– Page title. -
<!-- s2_meta -->– Meta tags with keywords and the description specified for the page. -
<!-- s2_date -->– Page creation date. -
<!-- s2_author -->– Author name. Displays the name assigned to the user in the control panel. -
<!-- s2_text -->– HTML code of the main content.
-
<!-- s2_head_title -->– Automatically generated title. Contains the page title and the site name. Intended for insertion into the title tag. -
<!-- s2_crumbs -->– Breadcrumbs—a chain of links to sections (ancestors of all levels). -
<!-- s2_section_link -->– Link to the section (immediate ancestor). -
<!-- s2_menu -->– Navigation links to other pages in the section. -
<!-- s2_back_forward -->– Links to the previous and next pages in the section. -
<!-- s2_article_tags -->– Works for pages tagged with keywords. Corresponds to a list of links to other articles with the same keywords. -
<!-- s2_tags -->– An alternative way to work with keywords. Creates a list of links to keyword pages with excerpts of the corresponding pages. -
<!-- s2_subarticles -->– Works only in sections. Corresponds to a list of articles with excerpts and a list of child sections. -
<!-- s2_last_articles -->– List of the latest pages across the site (titles, dates, excerpts). Used on the homepage in standard templates. Includes pages with specified creation or modification times.
-
<!-- s2_comments -->– User comments. -
<!-- s2_comment_form -->– Comment input form. -
<!-- s2_last_comments -->– List of the latest comments. Used on the homepage in standard templates. -
<!-- s2_last_discussions -->– List of pages (up to 10) with the most comments in the past month.
-
<!-- s2_site_title -->– Site name. Can be changed in the control panel under site settings. -
<!-- s2_styles -->– Place for linking styles and scripts (e.g., link tags for CSS files). Content is determined by the selected style and installed extensions. -
<!-- s2_navigation_link -->–<link rel="top|up|next|prev" href="proxy.php?url=https%3A%2F%2Fgithub.com%2F..." />tags with links to neighboring pages. -
<!-- s2_rss_link -->–<link rel="alternate" type="application/rss+xml" href="proxy.php?url=https%3A%2F%2Fgithub.com%2F..." />tag for RSS feed. -
<!-- s2_debug -->– Debug information about database queries. Only displayed when the constant S2_SHOW_QUERIES is enabled in config.php. -
<!-- s2_querytime -->– Page generation time and number of database queries. Only displayed when the constant S2_DEBUG is enabled. -
<!-- s2_copyright -->– Copyright notice for the site content and engine information. Parameters for this string can be modified in the admin panel under site settings.