Template API
The SLAED CMS Template API provides functions for rendering pages, handling themes, and managing user interface elements.
Table of Contents
Basic Template Functions
Core template functions for theme management:
// Include theme files
function setThemeInclude() {
global $theme;
$theme = get_theme();
include_once('templates/'.$theme.'/index.php');
include_once('core/template.php');
}
// Get current theme
$current_theme = get_theme();
// Find image in theme directories
function img_find($image_name, $default = '') {
$paths = array(
'uploads/'.$image_name,
'templates/'.get_theme().'/images/'.$image_name,
'templates/default/images/'.$image_name
);
foreach ($paths as $path) {
if (file_exists($path)) {
return $path;
}
}
return $default;
}
Template Rendering
Functions for rendering template elements:
// Basic template rendering
function setTemplateBasic($type, $values = array()) {
// $type: 'title', 'content', 'pagination', etc.
// $values: array of placeholder => value pairs
}
// Page title
$content = setTemplateBasic('title', array('{%title%}' => 'Page Title'));
// Content block
$content = setTemplateBasic('content', array(
'{%title%}' => $title,
'{%content%}' => $content,
'{%author%}' => $author,
'{%date%}' => format_time($timestamp)
));
Navigation and Pagination
Functions for handling navigation elements:
// Generate page numbers
function setPageNumbers($current, $module, $total_items, $total_pages, $per_page, $param = '', $max_links = 8, $anchor = '') {
// Returns pagination HTML
}
// Example usage
$page = getVar('get', 'page', 'num', 1);
$per_page = 10;
$total_items = 150;
$total_pages = ceil($total_items / $per_page);
$pagination = setPageNumbers($page, 'news', $total_items, $total_pages, $per_page);
echo $pagination;
// Lower navigation (back, home, top)
echo setNaviLower('module_name');
Messages and Warnings
Functions for displaying system messages:
// Warning/message templates
function setTemplateWarning($type, $values = array()) {
// $type: 'info', 'warn', 'error', 'success'
// $values: message parameters
}
// Success message
echo setTemplateWarning('success', array(
'text' => 'Operation completed successfully',
'url' => 'index.php?name=module',
'time' => '3'
));
// Error message
echo setTemplateWarning('error', array(
'text' => 'An error occurred',
'url' => 'javascript:history.back()',
'time' => '5'
));
Page Structure
Functions for managing page structure:
// Start HTML output (header, navigation)
head();
// Your content here
echo 'Module Content
';
echo 'Your module content...
';
// End HTML output (footer)
foot();
The Template API ensures consistent rendering across all modules and themes while providing flexibility for customization.