5 Steps to Get Ready for Latte 3

Found a typo? Edit me

After 3 months of intensive testing, David released Latte 3.0 two days ago, with massive evolution under the hood. We've been using it in Amateri past weeks, and today I will share our experience with you about how to get prepared for it.

Today, our goal is not to get your project to Latte 3. Developers of Latte Extensions will need a few weeks to catch up with the upgrade and test it, as macros have entirely new syntax.

Despite that, there are a few steps that we can do before the upgrade itself to prepare for boarding the beautiful ship called Latte 3.

1. Replace {ifCurrent ...} with {if isLinkCurrent(...)}

The macro ifCurrent calls function isLinkCurrent on the background. It will trigger an error in Latte 3.

Now, use the function directly instead:

 <a href="/friends" class="
-    {ifCurrent friends}active{/ifCurrent}
+    {if isLinkCurrent('friends')}active{/if}

And also:

-{ifCurrent 'meeting:lunch'}eat{/ifCurrent}
+{if isLinkCurrent('meeting:lunch')}win{/if}

💡 Tip: Do you use PHPStorm? This is the regex that handles change for you.

There is a particular case for the n:ifCurrent macro that is better to handle manually:

-<a href="/profile/change-password" n:ifCurrent="profile">Change Password</a>
+{if isLinkCurrent('profile')}
+    <a href="/profile/change-password">Change Password</a>

2. Get the Latest Latte 2.* version

This version is the latest you can get from 2.11.*. It does not break anything, and it helps you with the upgrade:

composer require latte/latte:^2.11.3

Do you have it in your project? Great, now we can use it in the next step ↓

3. Try Latte Linter Today

Syntax changes are described in this forum post, but how many of those are actually in our project? Maybe all of them? In our case it was just 4.

But how can we find them quickly? With the new Latte linter command. Just run it in CLI:

vendor/bin/latte-lint templates

During our testing, we assumed linter is an intelligent static analyzer (like PHPStan) that will not let us make mistakes. That's not the case.

The linter only checks the syntax of the Latte language is valid. It does not have the context or logic of your Latte files. Something like php -l.

Latte linter has a few spots to improve:

vendor/bin/latte-lint templates/single-file.latte

David is committing improvement coming the last 2 days, so upcoming patch versions might change it.

Latte syntax is now CASE sensitive and the Linter will tell you where it matters:

-{foreach $items AS $item}
+{foreach $items as $item}

Let me know in the comments what deprecations you've found in your code.

4. Prepare for the Translations

Since Latte 3, there are few changes in translate macros as we know them:


The single _ still works, but the dual _ macro will be replaced by translate:

-{_}Nice tree! How do you grow it?{/_}
+{translate}Nice tree! How do you grow it?{/translate}

The _, - or : could be part the language syntax. I think this is an improvement, as "translate" is self-explanatory.

Warning: the translate macro is not yet available in Latte 2.x. I think it's worth mentioning, as in our case, it means a change of hundreds of cases, and we have to prepare a plan to get ready for it.

5. Ping Your Latte 3.* Dependencies

Let's say our project is ready, we've updated all macros, Latte syntax, and Latte linter works. We want to board Latte 3...

But what about the external Latte extensions we use? We can find out easily by triggering the requirements:

composer require latte/latte:^3.0

Does the install pass? Congratulations, there is no blocker in your vendor and you're ready to sail!

Has the composer reported some conflicts?

Help out these packages to:

The sooner these packages are ready and tagged, the sooner whole Latte 3 community can sail together.

How to upgrade a Latte extension to Latte 3? Stay tuned for the next post. If you want to know earlier, we are looking for a new lazy and curious PHP colleague.

Happy coding!

Have you find this post useful? Do you want more?

Follow me on Twitter, RSS or support me on GitHub Sponsors.