Skip to content

Commit 2c1ae3b

Browse files
committed
tests: added test for snippet & block
1 parent 84112fd commit 2c1ae3b

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed
+14
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+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
// source: %A%
3+
4+
class Template%a% extends Latte\Template
5+
{
6+
7+
function render()
8+
{
9+
%A%
10+
// prolog Latte\Macros\BlockMacros
11+
$_b->blocks['_snippet'][] = [$this, 'block__snippet_%h%'];
12+
13+
$_b->blocks['block1'][] = [$this, 'block_block1_%h%'];
14+
15+
$_b->blocks['_outer'][] = [$this, 'block__outer_%h%'];
16+
17+
$_b->blocks['block2'][] = [$this, 'block_block2_%h%'];
18+
19+
// template extending
20+
21+
$_l->extends = empty($_g->extended) && isset($_control) && $_control instanceof Nette\Application\UI\Presenter ? $_control->findLayoutTemplateFile() : NULL; $_g->extended = TRUE;
22+
23+
if ($_l->extends) { ob_start(function () {});}
24+
25+
// main template
26+
if ($_l->extends) { ob_end_clean(); return $this->renderChildTemplate($_l->extends, get_defined_vars()); }
27+
call_user_func(reset($_b->blocks['_snippet']), $_b, $this->params) ?>
28+
29+
30+
<div id="<?php echo $_control->getSnippetId('outer') ?>"><?php call_user_func(reset($_b->blocks['_outer']), $_b, $this->params) ?>
31+
</div><?php
32+
}
33+
34+
35+
function block__snippet_%h%($_b, $_args)
36+
{
37+
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
38+
$_control->redrawControl('snippet', FALSE);
39+
40+
41+
}
42+
43+
44+
function block_block1_%h%($_b, $_args)
45+
{
46+
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v
47+
?><div<?php echo ' id="' . $_control->getSnippetId('snippet') . '"' ?>>
48+
static
49+
</div>
50+
<?php
51+
}
52+
53+
54+
function block__outer_%h%($_b, $_args)
55+
{
56+
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
57+
$_control->redrawControl('outer', FALSE)
58+
?>begin
59+
end
60+
<?php if (isset($_l->dynSnippets)) return $_l->dynSnippets;
61+
}
62+
63+
64+
function block_block2_%h%($_b, $_args)
65+
{
66+
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v
67+
?><div<?php echo ' id="' . ($_l->dynSnippetId = $_control->getSnippetId("inner-$id")) . '"' ?>>
68+
dynamic
69+
</div>
70+
<?php
71+
}
72+
73+
}
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)