Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

smarty_internal_compile_child.php 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /*
  3. * This file is part of Smarty.
  4. *
  5. * (c) 2015 Uwe Tews
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. /**
  11. * Smarty Internal Plugin Compile Child Class
  12. *
  13. * @author Uwe Tews <uwe.tews@googlemail.com>
  14. */
  15. class Smarty_Internal_Compile_Child extends Smarty_Internal_CompileBase
  16. {
  17. /**
  18. * Attribute definition: Overwrites base class.
  19. *
  20. * @var array
  21. * @see Smarty_Internal_CompileBase
  22. */
  23. public $optional_attributes = array('assign');
  24. /**
  25. * Tag name
  26. *
  27. * @var string
  28. */
  29. public $tag = 'child';
  30. /**
  31. * Block type
  32. *
  33. * @var string
  34. */
  35. public $blockType = 'Child';
  36. /**
  37. * Compiles code for the {child} tag
  38. *
  39. * @param array $args array with attributes from parser
  40. * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
  41. * @param array $parameter array with compilation parameter
  42. *
  43. * @return string compiled code
  44. * @throws \SmartyCompilerException
  45. */
  46. public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
  47. {
  48. // check and get attributes
  49. $_attr = $this->getAttributes($compiler, $args);
  50. $tag = isset($parameter[0]) ? "'{$parameter[0]}'" : "'{{$this->tag}}'";
  51. if (!isset($compiler->_cache[ 'blockNesting' ])) {
  52. $compiler->trigger_template_error("{$tag} used outside {block} tags ",
  53. $compiler->parser->lex->taglineno);
  54. }
  55. $compiler->has_code = true;
  56. $compiler->suppressNocacheProcessing = true;
  57. if ($this->blockType === 'Child') {
  58. $compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ][ 'callsChild' ] = 'true';
  59. }
  60. $_assign = isset($_attr[ 'assign' ]) ? $_attr[ 'assign' ] : null;
  61. $output = "<?php \n";
  62. if (isset($_assign)) {
  63. $output .= "ob_start();\n";
  64. }
  65. $output .= '$_smarty_tpl->inheritance->call' . $this->blockType . '($_smarty_tpl, $this' .
  66. ($this->blockType === 'Child' ? '' : ", {$tag}"). ");\n";
  67. if (isset($_assign)) {
  68. $output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n";
  69. }
  70. $output .="?>\n";
  71. return $output;
  72. }
  73. }