<! DOCTYPE html PUBLIC "- // W3C // DTD XHTML 1.0 Strict // EN" " www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd " >
< html xmlns = " www.w3.org/1999/xhtml " >
< head >
< title > Main title {if i $ ADDITIONAL_TITLE} | {$ ADDITIONAL_TITLE} {/ if} </ title >
< base href = "{$ ROOT_URL}" />
< meta http-equiv = "Content-Type" content = "text / html; charset = UTF-8 " />
</ head >
< body >
< div id = "base_div" >
< div id = "header_logo_div" > {include file = "header_logo.tpl"} </ div >
< div >
< div id = "user_login_info" > {include file = "users / user_login_info.tpl"} </ div >
< div id = "lang_selector" > {include file = "lang / selector.tpl"} </ div >
</ div >
< div >
< div id = "main_block" >
{include file = $ __ file_to_display}
</ div >
</ div >
</ div >
* This source code was highlighted with Source Code Highlighter .
<?php
abstract class smarty_page_ex extends Smarty {
protected $module ;
protected $action ;
public function __construct ( $module = "" , $action = "" , smarty_config_wrapper $config = null ) {
parent :: Smarty ();
$this -> module = $module ;
$this -> action = $action ;
$gconfig = global_config :: get_instance ();
if ( $config === null ) $config = $gconfig -> get_smarty_config ();
$this -> compile_check = $config -> get_tpl_compile_check ();
$this -> debugging = $config -> get_smarty_debug ();
$this -> compile_dir = $config -> get_tpl_compiled_path ();
$this -> cache_dir = $config -> get_tpl_cache_path ();
$this -> template_dir = $config -> get_tpl_path ();
$this -> config_dir = $config -> get_tpl_config_path ();
$lang = lang :: get_instance ();
$this -> assign_by_ref ( "lang" , $lang );
$this -> assign ( "ROOT_URL" , $gconfig -> root_url );
$this -> assign ( "MODULE" , $module );
$this -> assign ( "ACTION" , $action );
$this -> register_object ( "smarty_page_ex" , $this );
}
/**
* Gets template full path
*
* @param string $base_path
* @return string
*/
protected function get_full_path () {
return ( strlen ( $this -> module ) > 0 ? ( $this -> module . "/" ) : "" );
}
}
?>
<templates-dir>/
|-<module>
| |-<action>.tpl
|-home
| |-index.tpl
|-common_page.tpl
|-admin_page.tpl
|-mail_page.tpl
<?php
class common_page extends smarty_page_ex {
public function __construct ( $module = "" , $action = "" , $title = "" , smarty_config_wrapper $config = null ) {
parent :: __construct ( $module , $action , $config );
$options = options :: get_instance ();
$this -> assign_by_ref ( "options" , $options );
$auth_user = auth_user :: get_instance ();
$this -> assign_by_ref ( "auth_user" , $auth_user );
$gconfig = global_config :: get_instance ();
$this -> assign_by_ref ( "gconfig" , $gconfig );
$lang = new languages ();
$lang_list = db_adapter :: get_instance ()-> get_list ( $lang );
$this -> assign_by_ref ( "__languages" , $lang_list );
$this -> assign ( "ADDITIONAL_TITLE" , $title );
}
/**
* Executes & returns or displays the template results
*
* @param string $template
* @param string $cache_id
* @param string $compile_id
* @param boolean $display
*/
public function fetch ( $template , $cache_id = null , $compile_id = null , $display = false ) {
$this -> assign ( "__file_to_display" , $this -> get_full_path () . $template );
return parent :: fetch ( "common_page.tpl" , $cache_id , $compile_id , $display );
}
}
?>
<?php
$tpl = new common_page ( "home" , "index" , "Welcome!" );
$tpl -> display ();
?>
Source: https://habr.com/ru/post/38174/
All Articles