mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Fix #249
This commit is contained in:
parent
514b0b6769
commit
cd4f688088
@ -5,11 +5,73 @@ require_once __DIR__.'/../tests/tools.php';
|
||||
|
||||
\Fenom::registerAutoload();
|
||||
|
||||
$vars = [
|
||||
[
|
||||
"id" => 1,
|
||||
"name" => "Блаблабла",
|
||||
"hidden_url" => "/"
|
||||
],
|
||||
[
|
||||
"id" => 2,
|
||||
"name" => "Каталог",
|
||||
"hidden_url" => "/catalog"
|
||||
],
|
||||
[
|
||||
"id" => 3,
|
||||
"name" => "Сыромолочная группа",
|
||||
"hidden_url" => "/catalog/cat_1.html"
|
||||
],
|
||||
[
|
||||
"id" => 4,
|
||||
"name" => "Сыры",
|
||||
"hidden_url" => "/catalog/cat_2.html"
|
||||
],
|
||||
];
|
||||
|
||||
$fenom = Fenom::factory(__DIR__.'/templates', __DIR__.'/compiled');
|
||||
$fenom->setOptions(Fenom::AUTO_RELOAD | Fenom::FORCE_VERIFY);
|
||||
//var_dump($fenom->compile("nested.tpl", [])->getTemplateCode());
|
||||
//exit;
|
||||
var_dump($fenom->fetch('bug247/home.tpl', []));
|
||||
var_dump($fenom->fetch('bug249/bread.tpl', ["arr" => $vars]));
|
||||
//var_dump($fenom->compile('bug249/bread.tpl', false)->getBody());
|
||||
//var_dump($fenom->compile("bug158/main.tpl", [])->getTemplateCode());
|
||||
//var_dump($fenom->display("bug158/main.tpl", []));
|
||||
// $fenom->getTemplate("problem.tpl");
|
||||
|
||||
/*
|
||||
*
|
||||
* Array
|
||||
(
|
||||
[0] => Array
|
||||
(
|
||||
[id] => 1
|
||||
[name] => Блаблабла
|
||||
[hidden_url] => /
|
||||
)
|
||||
[1] => Array
|
||||
(
|
||||
[id] => 2
|
||||
[name] => Каталог
|
||||
[hidden_url] => /catalog/
|
||||
)
|
||||
[2] => Array
|
||||
(
|
||||
[orig_id] => 1
|
||||
[hidden_url] => /catalog/cat_1.html
|
||||
[name] => Сыромолочная группа
|
||||
)
|
||||
[3] => Array
|
||||
(
|
||||
[orig_id] => 2
|
||||
[hidden_url] => /catalog/cat_2.html
|
||||
[name] => Сыры
|
||||
)
|
||||
[4] => Array
|
||||
(
|
||||
[orig_id] => 6
|
||||
[hidden_url] => /catalog/cat_6.html
|
||||
[name] => Сыр плавленый
|
||||
)
|
||||
)
|
||||
|
||||
*/
|
38
sandbox/templates/bug249/bread.tpl
Normal file
38
sandbox/templates/bug249/bread.tpl
Normal file
@ -0,0 +1,38 @@
|
||||
{*<div class='bread'>*}
|
||||
{*<ul>*}
|
||||
{*<li><a href='/'>Главная</a><li>*}
|
||||
{*{foreach 1..$arr|length as $counter index=$i first=$first last=$last}*}
|
||||
{*{if !$first}*}
|
||||
{*<li class='delim'>/</li>*}
|
||||
{*<li>{$last}*}
|
||||
{*{if !$last}*}
|
||||
{*<a href='{$arr[$i]['hidden_url']}'>{else}<span>*}
|
||||
{*{/if}*}
|
||||
{*{$arr[$i]['name']}{if !$last}</a>{else}</span>{/if}</li>{/if}*}
|
||||
{*{/foreach}*}
|
||||
{*</ul>*}
|
||||
{*</div>*}
|
||||
|
||||
=== {(1..3)|length} ===
|
||||
|
||||
{foreach 1..3 as $c index=$i first=$first last=$last}
|
||||
{$i}: {$last}
|
||||
{/foreach}
|
||||
|
||||
<div class='bread'>
|
||||
<ul>
|
||||
<li><a href='/'>Главная</a><li>
|
||||
{foreach $arr as $item first=$first last=$last}
|
||||
{if !$first}
|
||||
<li class='delim'>/</li>
|
||||
<li>{$last}
|
||||
{if $last}
|
||||
<span>{$item.name}</span>
|
||||
{else}
|
||||
<a href='{$item.hidden_url}'>{$item.name}</a>
|
||||
{/if}
|
||||
</li>
|
||||
{/if}
|
||||
{/foreach}
|
||||
</ul>
|
||||
</div>
|
@ -90,7 +90,7 @@ class RangeIterator implements \Iterator, \Countable
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return intval(($this->max - $this->min) / $this->step);
|
||||
return intval(($this->max - $this->min + 1) / $this->step);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1406,6 +1406,11 @@ class TemplateTest extends TestCase
|
||||
$a,
|
||||
'Foreach: 0 => 1, 1 => 2, 2 => 3, end'
|
||||
),
|
||||
array(
|
||||
'Foreach: {foreach 1..3 as $k => $e last=$l} {$k} => {$e}, {if $l}last{/if} {/foreach} end',
|
||||
$a,
|
||||
'Foreach: 0 => 1, 1 => 2, 2 => 3, last end'
|
||||
),
|
||||
array(
|
||||
'Foreach: {foreach $.get.items as $e} {$e}, {/foreach} end',
|
||||
$a,
|
||||
|
Loading…
Reference in New Issue
Block a user