Add support for Blade-style @each include loop

This commit is contained in:
Kijin Sung 2023-10-17 02:26:06 +09:00
parent eba9a4d333
commit 668feea9e9
7 changed files with 56 additions and 4 deletions

View file

@ -0,0 +1 @@
<div>{$var}</div>

View file

@ -0,0 +1 @@
<div>Empty</div>

View file

@ -39,6 +39,9 @@
<div>Nothing here...</div>
@end
@each('incl/eachtest', $bar, 'var')
@each('incl/eachtest', [], 'anything', 'incl/empty')
@desktop
<p>The full class name is {get_class(new Push)|escape}, {Push::class} really.</p>
@enddesktop

View file

@ -28,7 +28,7 @@
<?php endif; ?>
</div>
<?php $__tmp_19148045bac5d8 = Context::get('bar') ?? []; if($__tmp_19148045bac5d8): foreach ($__tmp_19148045bac5d8 as $__Context->k => $__Context->val): ?>
<?php $__tmp_042521f3da7d65 = Context::get('bar') ?? []; if($__tmp_042521f3da7d65): foreach ($__tmp_042521f3da7d65 as $__Context->k => $__Context->val): ?>
<div>
<?php if (empty($__Context->nosuchvar)): ?>
<img src="/rhymix/tests/_data/template/bar/rhymix.svg" alt="unit tests are cool" />
@ -39,6 +39,9 @@
<div>Nothing here...</div>
<?php endif; ?>
<?php (function($__dir, $__path, $__vars, $__varname, $__empty = null) { if (!$__vars): $__vars = []; if ($__empty): $__path = $__empty; $__vars[] = ''; endif; endif; foreach ($__vars as $__var): $__tpl = new \Rhymix\Framework\Template($__dir, $__path, "html"); $__tpl->setVars([(string)$__varname => $__var]); echo $__tpl->compile(); endforeach; })($this->relative_dirname, 'incl/eachtest', $__Context->bar, 'var'); ?>
<?php (function($__dir, $__path, $__vars, $__varname, $__empty = null) { if (!$__vars): $__vars = []; if ($__empty): $__path = $__empty; $__vars[] = ''; endif; endif; foreach ($__vars as $__var): $__tpl = new \Rhymix\Framework\Template($__dir, $__path, "html"); $__tpl->setVars([(string)$__varname => $__var]); echo $__tpl->compile(); endforeach; })($this->relative_dirname, 'incl/eachtest', [], 'anything', 'incl/empty'); ?>
<?php if (!$__Context->m): ?>
<p>The full class name is <?php echo htmlspecialchars(get_class(new Rhymix\Framework\Push), \ENT_QUOTES, 'UTF-8', true); ?>, <?php echo htmlspecialchars(Rhymix\Framework\Push::class, \ENT_QUOTES, 'UTF-8', false); ?> really.</p>
<?php endif; ?>

View file

@ -40,6 +40,13 @@
<span class="BEST!"></span>
</div>
<div>Rhy</div>
<div>miX</div>
<div>is</div>
<div>da</div>
<div>BEST!</div>
<div>Empty</div>
<p>The full class name is Rhymix\Framework\Push, Rhymix\Framework\Push really.</p>
<div class="barContainer" data-bar="[&quot;Rhy&quot;,&quot;miX&quot;,&quot;is&quot;,&quot;da&quot;,&quot;BEST!&quot;]"></div>