function cw_display($tpl, &$templater, $to_display = true, $lng_code = '')
{
    global $config, $location, $HTTPS;
    global $predefined_lng_variables, $current_language, $__smarty_time, $__smarty_size;
    global $app_main_dir;
    global $__X_LNG, $REQUEST_URI, $REQUEST_METHOD;
    global $ars_hooks;
    global $target, $action;
    if ($to_display) {
        cw_event('on_after_' . $target);
        cw_event('on_after_' . $target . '_' . $action);
    }
    $include = array('css' => array(), 'js' => array());
    if (is_array($ars_hooks['css']['all'])) {
        $include['css'] = array_merge($include['css'], $ars_hooks['css']['all']);
    }
    if (is_array($ars_hooks['css'][AREA_TYPE])) {
        $include['css'] = array_merge($include['css'], $ars_hooks['css'][AREA_TYPE]);
    }
    if (is_array($ars_hooks['js']['all'])) {
        $include['js'] = array_merge($include['js'], $ars_hooks['js']['all']);
    }
    if (is_array($ars_hooks['js'][AREA_TYPE])) {
        $include['js'] = array_merge($include['js'], $ars_hooks['js'][AREA_TYPE]);
    }
    $templater->assign('include', $include);
    $templater->assign('config', $config);
    $templater->assign('location', $location);
    $templater->assign('lng', array());
    cw_load('templater');
    if (!empty($config['Security']['compiled_tpl_check_md5']) && $config['Security']['compiled_tpl_check_md5'] == 'Y') {
        $templater->compile_check_md5 = true;
    } else {
        $templater->compile_check_md5 = false;
    }
    if (!empty($predefined_lng_variables)) {
        if (empty($lng_code)) {
            $lng_code = $current_language;
        }
        if (!empty($predefined_lng_variables)) {
            $predefined_lng_variables = array_flip($predefined_lng_variables);
            $predefined_vars = array();
            cw_get_lang_vars_extra($lng_code, $predefined_lng_variables, $predefined_vars);
            $templater->_tpl_vars['lng'] = cw_array_merge($templater->_tpl_vars['lng'], $predefined_vars);
            if (!isset($__X_LNG[$current_language])) {
                $__X_LNG[$current_language] = $predefined_vars;
            } else {
                $__X_LNG[$current_language] = cw_array_merge($__X_LNG[$current_language], $predefined_vars);
            }
            unset($predefined_vars);
        }
        unset($predefined_lng_variables);
    }
    $templater->register_postfilter("cw_tpl_add_hash");
    $templater->register_postfilter('cw_tpl_postfilter');
    $templater->register_outputfilter('cw_convert_lang_var');
    $templater->register_outputfilter('cw_generate_css_sprites');
    $templater->load_filter('post', 'cw_hooks');
    $templater->register_outputfilter('cw_load_head_resource');
    global $current_area;
    if ($config['General']['defer_load_js_code'] == 'Y' && $current_area == 'C' && !(defined('IS_AJAX') && constant('IS_AJAX'))) {
        $templater->register_outputfilter('cw_defer_load_js_code');
    }
    if ($config['General']['sprite_all_images'] == 'Y' && $current_area == 'C' && !(defined('IS_AJAX') && constant('IS_AJAX'))) {
        $templater->register_outputfilter('cw_sprite_all_images');
    }
    if ($config['General']['list_available_cdn_servers'] && !$HTTPS) {
        $templater->register_outputfilter('cw_sharing_cdn');
    }
    cw_track_navigation_history($REQUEST_URI, $REQUEST_METHOD, TRUE);
    if ($to_display == true) {
        $templater->display($tpl);
        $ret = "";
        # Display page content
        cw_flush();
    } else {
        $ret = $templater->fetch($tpl);
    }
    return $ret;
}
function cw_tpl_build_lang($hash_file, $vars_names, $lng_code)
{
    global $config, $current_area;
    $variables = array_flip($vars_names);
    $add_lng = array();
    cw_get_lang_vars_extra($lng_code, $variables, $add_lng);
    #
    # Store retrieved language variables into hash file
    #
    $data = serialize($add_lng);
    $data = md5($hash_file . $data) . $data;
    $fp = fopen($hash_file, "wb");
    if ($fp === false) {
        return;
    }
    fwrite($fp, $data);
    fclose($fp);
}