PHP Classes

File: lib/internal/compile.include.php

Recommend this page to a friend!
  Packages of David Tamas   g-template-php   lib/internal/compile.include.php   Download  
File: lib/internal/compile.include.php
Role: Example script
Content type: text/plain
Description: Example script
Class: g-template-php
Process and render templates generating PHP code
Author: By
Last change:
Date: 8 years ago
Size: 1,626 bytes
 

 

Contents

Class file image Download
<?php
/**
 * gTemplate Internal Function
 * Compiles the 'include' function
 *
 * @package    gTemplate
 * @subpackage internalFunctions
 */

function compile_include($arguments, &$gTpl) {
    $_args = $gTpl->_parse_arguments($arguments);

    $arg_list = array();
    if (empty($_args['file'])) {
        $gTpl->trigger_error("[SYNTAX] missing 'file' attribute in 'include' tag", E_USER_ERROR, $gTpl->_file, $gTpl->_linenum);
    }

    foreach ($_args as $arg_name => $arg_value) {
        if ($arg_name == 'file') {
            $include_file = $arg_value;
            continue;

        } else if ($arg_name == 'assign') {
            $assign_var = $arg_value;
            continue;
        }

        if (is_bool($arg_value)) {
            $arg_value = $arg_value ? 'true' : 'false';
        }
        $arg_list[] = "'$arg_name' => $arg_value";
    }

    if (isset($assign_var)) {
        $output = "<?php \n"
                . "/* START of Subtemplate include: {$include_file} */\n"
                . '$gTpl->assign(' . $assign_var . ', $gTpl->_fetch_compile_include(' . $include_file . ', array(' . implode(',', (array) $arg_list) . ')));' . "\n"
                . "/* END of Subtemplate include: {$include_file} */\n"
                . ' ?>';
    } else {
        $output = "<?php \n"
                . "/* START of Subtemplate include: {$include_file} */\n"
                . 'echo $gTpl->_fetch_compile_include(' . $include_file . ', array(' . implode(',', (array) $arg_list) . '));' . "\n"
                . "/* END of Subtemplate include: {$include_file} */\n"
                . ' ?>';
    }
    return $output;
}