Bake Template creates multiple hundret spaces

Hi,
I’m trying to create my own bake template theme. Everything is seemingly working fine, but the generated HTML will not pass the verification of phpcs, because it somehow creates multiple hundret spaces and i don’t know why.

This is an example error:

------------------------------------------------------------------------------
 37 | ERROR | [x] Line indented incorrectly; expected at least 216 spaces,
    |       |     found 40

This is my bake template of the wrong part:

                <?php foreach (${{ pluralVar }} as ${{ singularVar }}) : ?>
                <tr>
                    {% for field in fields %}
                        {% set isKey = false %}
                        {% if associations.BelongsTo is defined %}
                            {% for alias, details in associations.BelongsTo %}
                                {% if field == details.foreignKey %}
                                    {% set isKey = true %}
                                    <td><?= ${{ singularVar }}->has('{{ details.property }}') ?
                                        $this->Html->link(${{ singularVar }}->{{ details.property }}
                                        ->{{ details.displayField }}, ['controller' => '{{ details.controller }}',
                                        'action' => 'view', ${{ singularVar }}->{{ details.property }}
                                        ->{{ details.primaryKey[0] }}]) : '' ?>
                                    </td>
                                {% endif %}
                            {% endfor %}
                        {% endif %}

This is the wrong generated HTML:

                <?php foreach ($users as $user) : ?>
                <tr>
                                                                                                                                                                                                                                                                                                    <td><?= $this->Number->format($user->id) ?></td>
                                                                                                                                                                                                                                                                                                                                                        <td><?= h($user->firstname) ?></td>
                                                                                                                                                                                                                                                                                                                                                        <td><?= h($user->lastname) ?></td>
                                                                                                                                                                                                                                                            <td><?= $user->has('role') ?
                                        $this->Html->link($user->role
                                        ->name, ['controller' => 'Roles',
                                        'action' => 'view', $user->role
                                        ->id]) : '' ?>
                                    </td>
                                                                                                                                                                                                                                                                                                                                                                                                                <td><?= h($user->email) ?></td>
                                                                                                                                                                                                                                                                                                                                                        <td><?= h($user->created) ?></td>
                                                                                                                                                                                                                                                                                                                                                        <td><?= h($user->modified) ?></td>
                                                                                                                                                                                                                                                                                                                                                        <td><?= h($user->active) ?></td>
                                                                                                                <td class="actions">

It’s preserving all of the leading spaces on all the lines starting with {%. If you look at the standard bake templates, they all have those lines at the left margin.

1 Like

Thank you very much. I redid them and now it’s working