Migration from PHP to Latte

Are you migrating an old project written in pure PHP to Latte? We have a tool to make the migration easier. Try it out online.

You can download the tool from GitHub or install it using Composer:

composer create-project latte/tools

The converter does not use simple regular expression substitutions, instead it uses the PHP parser directly, so it can handle any complex syntax.

The script php-to-latte.php is used to convert from PHP to Latte:

php-to-latte.php input.php [output.latte]

Example

The input file might look like this (it is part of the PunBB forum code):

<h1><span><?= $lang_common['User list'] ?></span></h1>

<div class="blockform">
	<form id="userlist" method="get" action="userlist.php">
		<div class="infldset">
<?php
foreach ($result as $cur_group) {
	if ($cur_group['g_id'] == $show_group) {
		echo "\n\t\t" . '<option value="' . $cur_group['g_id'] . '" selected="selected">'
			. htmlspecialchars($cur_group['g_title']) . '</option>';
	} else {
		echo "\n\t\t" . '<option value="' . $cur_group['g_id'] . '">'
			. htmlspecialchars($cur_group['g_title']) . '</option>';
	}
}
?>
			</select>
			<p class="clearb"><?= $lang_ul['User search info'] ?></p>
		</div>
	</form>
</div>

Generates this template:

<h1><span>{$lang_common['User list']}</span></h1>

<div class="blockform">
	<form id="userlist" method="get" action="userlist.php">
		<div class="infldset">
{foreach $result as $cur_group}
    {if $cur_group[g_id] == $show_group}
		<option value="{$cur_group[g_id]}" selected="selected">{$cur_group[g_title]}</option>
     {else}
		<option value="{$cur_group[g_id]}">{$cur_group[g_title]}</option>
    {/if}
{/foreach}			</select>
			<p class="clearb">{$lang_ul['User search info']}</p>
		</div>
	</form>
</div>