Skip to content

Parser is not able to handle nested loops #1799

Description

@hwiesmann

Describe the bug
The parser is not able to handle nested loops (code and output example below).

CodeIgniter 4 version
CodeIgniter4 Alpha 4

Affected module(s)
Parser

Expected behavior, and steps to reproduce if appropriate
Assume the following template

<table class="data_table">
  <thead>
    <tr>
      {header_entries}
        <th>{header_title}</th>
      {/header_entries}
    </tr>
  </thead>
  <tbody>
    {data_entries}
      <tr>
        {data_row}
          <td>{data_cell}</td>
        {/data_row}
      </tr>
    {/data_entries}
  </tbody>
</table>

with these input values and code:

   $header_entries = [['header_title' => 'one'],
                      ['header_title' => 'two']];
   $data_entries = [['data_row' => [['data_cell' => 'one - one'],
                                    ['data_cell' => 'one - two']],
                     'data_row' => [['data_cell' => 'two - one'],
                                    ['data_cell' => 'two - two']]]];
   $parser = \Config\Services::parser();
   echo $parser->setData(['header_entries' => $header_entries,
                          'data_entries' => $data_entries])->render('templates/data_table_template');

The expected output is:

one two
one - one one - two
two - one two - two

Unfortunately the output is
one two
two - one two - two

{header_entries} specifies a single loop. This works because the first line in the output is correct. {data_entries} and {data_row} specify an outer and an inner loop. The output of these loops is not correct.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions