You are here

function Smarty_Compiler::_compile_include_tag in Quiz 6.6

Same name and namespace in other branches
  1. 6.5 includes/moodle/lib/smarty/Smarty_Compiler.class.php \Smarty_Compiler::_compile_include_tag()

Compile {include ...} tag

Parameters

string $tag_args:

Return value

string

1 call to Smarty_Compiler::_compile_include_tag()
Smarty_Compiler::_compile_tag in includes/moodle/lib/smarty/Smarty_Compiler.class.php
Compile a template tag

File

includes/moodle/lib/smarty/Smarty_Compiler.class.php, line 952

Class

Smarty_Compiler
Template compiling class @package Smarty

Code

function _compile_include_tag($tag_args) {
  $attrs = $this
    ->_parse_attrs($tag_args);
  $arg_list = array();
  if (empty($attrs['file'])) {
    $this
      ->_syntax_error("missing 'file' attribute in include tag", E_USER_ERROR, __FILE__, __LINE__);
  }
  foreach ($attrs 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}";
  }
  $output = '<?php ';
  if (isset($assign_var)) {
    $output .= "ob_start();\n";
  }
  $output .= "\$_smarty_tpl_vars = \$this->_tpl_vars;\n";
  $_params = "array('smarty_include_tpl_file' => " . $include_file . ", 'smarty_include_vars' => array(" . implode(',', (array) $arg_list) . "))";
  $output .= "\$this->_smarty_include({$_params});\n" . "\$this->_tpl_vars = \$_smarty_tpl_vars;\n" . "unset(\$_smarty_tpl_vars);\n";
  if (isset($assign_var)) {
    $output .= "\$this->assign(" . $assign_var . ", ob_get_contents()); ob_end_clean();\n";
  }
  $output .= ' ?>';
  return $output;
}