New in Latte 2.7: types everywhere and batch

25 days ago by David Grudl     edit

A month after the release of Latte 2.6, which brought optional chaining and custom functions, there is Latte 2.7, which is even more interesting for the news.

Type system

Type system is a key thing for robust application development. To know what data or object type each variable is allows

  • IDE to correctly autocomplete
  • static analysis to detect errors

Both things significantly increase the quality and convenience of development. This topic deserves a separate article in which you will learn all the essentials: how to declare types, how to simplify your work and how to enable autocompletion in IDE.

Filter |batch

A new feature is the filter |batch, which simplifies the listing of linear data into a table:

{var $items = ['a', 'b', 'c', 'd', 'e', 'f', 'g']}
<table>
{foreach ($items|batch:3:'No item') as $row}
    <tr>
        {foreach $row as $column}
            <td>{$column}</td>
        {/foreach}
    </tr>
{/foreach}
</table>

generates:

<table>
    <tr>
        <td>a</td>
        <td>b</td>
        <td>c</td>
    </tr>
    <tr>
        <td>d</td>
        <td>e</td>
        <td>f</td>
    </tr>
    <tr>
        <td>g</td>
        <td>No item</td>
        <td>No item</td>
    </tr>
</table>

The first parameter is the number of columns and the second, optional, additional value to fill the last row.

And briefly

  • Optional chaining can now also be used for expressions like $obj->$var? and $obj::$var?
  • Using spaceless as n:attribute preserves whitespace before and after element <div n:spaceless>
  • All ILoader, IHtmlString, ISnipperDriver, IMacro interfaces can now be written without the I prefix. It is another step in the gradual elimination of prefixes throughout the framework.