增强loop标签可读性

This commit is contained in:
TOP糯米 2020-06-11 10:25:51 +08:00
parent 00b9d993a4
commit 24907af8e3
1 changed files with 2 additions and 2 deletions

View File

@ -18,7 +18,7 @@ class Tags
'php' => ['attr' => '', 'close' => 1],
'if' => ['attr' => 'condition', 'close' => 1],
'else' => ['attr' => 'condition', 'close' => 0],
'loop' => ['attr' => 'name,id,key', 'close' => 1],
'loop' => ['attr' => 'from,to,index,key', 'close' => 1],
'assign' => ['attr' => 'name,value', 'close' => 0],
'switch' => ['attr' => 'name', 'close' => 1],
'case' => ['attr' => 'value', 'close' => 1],
@ -104,7 +104,7 @@ class Tags
public function _loop($attr, $content)
{
$parse = '<?php ' . (isset($attr['key']) ? '$' . $attr['key'] . ' = 0; ' : '');
$parse .= 'foreach($' . $attr['name'] . ' as ' . (isset($attr['index']) ? '$' . $attr['index'] . '=>' : '') . '$' . $attr['id'] . '): ';
$parse .= 'foreach($' . $attr['from'] . ' as ' . (isset($attr['index']) ? '$' . $attr['index'] . '=>' : '') . '$' . $attr['to'] . '): ';
$parse .= (isset($attr['key']) ? '$' . $attr['key'] . '++;' : '') . ' ?>';
$parse .= $content;
$parse .= '<?php endforeach; ?>';