RainTPL循环进入循环

时间:2014-02-23 10:59:19

标签: php html template-engine

我必须使用循环进入子循环。我不能在父循环中使用子循环。

例如这是我的示例代码

{loop="user_list"}
  {$key} - {$value.name}</br>
  {loop="list"}
     {$key} - {$value.id}</br>
  {/loop}
{/loop}

1 个答案:

答案 0 :(得分:3)

Try adding $ to your variables.

{loop="$user_list"}
    {$key} - {$value.name}</br>
    {loop="$list"}
        {$key} - {$value.id}</br>
    {/loop}
{/loop}

Below one sample that worked for me with RainTPL3:

{loop="$letters"}
    {$key} - {$value.name}</br>
    {loop="$numbers"}
        {$key} - {$value.id}</br>
    {/loop}
{/loop}


- Input:
$letters = array( "A" => array("name" => "Letter A"),
                  "B" => array("name" => "Letter B"),
                  "C" => array("name" => "Letter C"));
$numbers = array(0 => array("id" => "Number 0"),
                 1 => array("id" => "Number 1"),
                 2 => array("id" => "Number 2")); 

- Output:

A - Letter A
0 - Number 0
1 - Number 1
2 - Number 2
B - Letter B
0 - Number 0
1 - Number 1
2 - Number 2
C - Letter C
0 - Number 0
1 - Number 1
2 - Number 2