Search code examples
cakephpcakephp-3.xpaginator

CakePHP 3: How to add a line break to Paginator sort links


I have a couple of columns on an index page where I would like to include line breaks.

<thead>
  <tr>
    <th><?= $this->Paginator->sort('name') ?></th>
    <th><?= $this->Paginator->sort('temp', ['label' => 'Temperature (C)']) ?></th>
    <th><?= $this->Paginator->sort('vol', ['label' => 'Volume (m^3)']) ?></th>
  </tr>
</thead>

What I would like is for the column "units" to be underneath the "unit name". Essentially, I want to replace the space before the units with a "br" tag.

Ideally, these "th" items should render out similar to the following:

<th>Temperature<br>(C)</th>
<th>Volume<br>(m^3)</th>

Recommendations?


Solution

  • This can be done like so:

    <?= $this->Paginator->sort('temp', 'Temperature<br>(C)', ['escape' => false]) ?>
    

    See the documentation for an example on using html in sort links.