Skip to content

Commit 7fcb78e

Browse files
committed
UIRuntime: created variable $template for back compatibility
1 parent 80bb845 commit 7fcb78e

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

src/Bridges/ApplicationLatte/UIRuntime.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class UIRuntime
2626
*/
2727
public static function initialize(Latte\Template $template, \stdClass $blocks = NULL)
2828
{
29+
// back compatiblity
30+
$template->params['template'] = new VariableTemplate($template);
31+
2932
// snippet support
3033
$params = $template->params;
3134
if (empty($params['_l']->extends) && !empty($params['_control']->snippetMode) && empty($params['_g']->includingBlock)) {
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Nette Framework (https://nette.org)
5+
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6+
*/
7+
8+
namespace Nette\Bridges\ApplicationLatte;
9+
10+
use Latte;
11+
12+
13+
/**
14+
* Variable $template for back compatibility.
15+
* @internal
16+
*/
17+
class VariableTemplate extends Template
18+
{
19+
/** @var Latte\Template */
20+
private $template;
21+
22+
23+
public function __construct(Latte\Template $template)
24+
{
25+
$this->template = $template;
26+
}
27+
28+
/**
29+
* Call a template run-time filter.
30+
*/
31+
public function __call($name, $args)
32+
{
33+
return call_user_func_array($this->template->filters->$name, $args);
34+
}
35+
36+
37+
/**
38+
* Sets a template parameter.
39+
* @return void
40+
*/
41+
public function __set($name, $value)
42+
{
43+
$this->template->params[$name] = $value;
44+
}
45+
46+
47+
/**
48+
* Returns a template parameter.
49+
* @return mixed value
50+
*/
51+
public function &__get($name)
52+
{
53+
if (!array_key_exists($name, $this->template->params)) {
54+
trigger_error("The variable '$name' does not exist in template.");
55+
}
56+
return $this->template->params[$name];
57+
}
58+
59+
60+
/**
61+
* Determines whether parameter is defined.
62+
* @return bool
63+
*/
64+
public function __isset($name)
65+
{
66+
return isset($this->template->params[$name]);
67+
}
68+
69+
70+
/**
71+
* Removes a template parameter.
72+
* @param string name
73+
* @return void
74+
*/
75+
public function __unset($name)
76+
{
77+
unset($this->template->params[$name]);
78+
}
79+
80+
}

0 commit comments

Comments
 (0)