Skip to content

Commit b42b3fe

Browse files
committed
tests: added test for snippet & block
1 parent 3a5f333 commit b42b3fe

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
use Tester\Assert;
4+
5+
6+
require __DIR__ . '/../bootstrap.php';
7+
8+
9+
$latte = new Latte\Engine;
10+
11+
Assert::matchFile(
12+
__DIR__ . '/expected/UIMacros.snippet4.phtml',
13+
$latte->compile(__DIR__ . '/templates/snippets.block.latte')
14+
);
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
// source: %A%
3+
4+
class Template%a% extends Latte\Template
5+
{
6+
public $_blocks = [
7+
'_snippet' => 'block__snippet_142fc55',
8+
'block1' => 'block_block1_9dd085e',
9+
'_outer' => 'block__outer_b1d040b',
10+
'block2' => 'block_block2_e0d89d3',
11+
];
12+
13+
14+
function render()
15+
{
16+
%A%
17+
$_l->extends = empty($_g->extended) && isset($_control) && $_control instanceof Nette\Application\UI\Presenter ? $_control->findLayoutTemplateFile() : NULL; $_g->extended = TRUE;
18+
19+
if ($_l->extends) { ob_start(function () {});}
20+
21+
// main template
22+
if ($_l->extends) { ob_end_clean(); return $this->renderChildTemplate($_l->extends, get_defined_vars()); }
23+
call_user_func(reset($_b->blocks['_snippet']), $_b, $this->params) ?>
24+
25+
26+
<div id="<?php echo $_control->getSnippetId('outer') ?>"><?php call_user_func(reset($_b->blocks['_outer']), $_b, $this->params) ?>
27+
</div><?php
28+
}
29+
30+
31+
function block__snippet_%h%($_b, $_args)
32+
{
33+
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
34+
$_control->redrawControl('snippet', FALSE);
35+
36+
37+
}
38+
39+
40+
function block_block1_%h%($_b, $_args)
41+
{
42+
?><div<?php echo ' id="' . $_control->getSnippetId('snippet') . '"' ?>>
43+
static
44+
</div>
45+
<?php
46+
}
47+
48+
49+
function block__outer_%h%($_b, $_args)
50+
{
51+
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
52+
$_control->redrawControl('outer', FALSE)
53+
?>begin
54+
end
55+
<?php if (isset($_l->dynSnippets)) return $_l->dynSnippets;
56+
}
57+
58+
59+
function block_block2_%h%($_b, $_args)
60+
{
61+
?><div<?php echo ' id="' . ($_l->dynSnippetId = $_control->getSnippetId("inner-$id")) . '"' ?>>
62+
dynamic
63+
</div>
64+
<?php
65+
}
66+
67+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div n:snippet="snippet" n:block="block1">
2+
static
3+
</div>
4+
5+
6+
{snippet outer}
7+
begin
8+
<div n:snippet="inner-$id" n:block="block2">
9+
dynamic
10+
</div>
11+
end
12+
{/snippet}

0 commit comments

Comments
 (0)