I am in the process of upgrading a PHP-based site from Smarty2 to Smarty3. I have managed to get most everything working on both versions by replacing require_once('Smarty.class.php'
with the following:
@ include_once('SmartyBC.class.php');
if (class_exists('SmartyBC')) {
$smarty = new SmartyBC();
//this is for use outside templates. inside templates, $smarty.version == 'Smarty-3.x.y.z'
$smartyVersion = 3;
}
//catch (Exception $e) {
else {
require_once('Smarty.class.php');
$smarty = new Smarty();
$smartyVersion = 2;
}
Then I have a symlink at /usr/local/lib/php/Smarty, that points to either version 2 or version 3. In order to swap between the two, I need only change the symlink. By using the compatibility layer class (SmartyBC) almost everything already works with both versions. I'd like to maintain compatibility with both versions until everything has been fully tested, and make as few changes to old templates as possible. With that in mind, here is the piece of code I am trying to upgrade:
//someinclude.php:
define('SOME_CONSTANT', 'someConst');
//somepage.tpl:
{if $dynVal == SOME_CONSTANT}dynamic content{/if}
This doesn't work in V3, but this will:
{if $dynVal == $smarty.const.SOME_CONSTANT}dynamic content{/if}
These constants (quite a few of them) are used all over the place, so ideally I'd like to find a way to make the first way work in version 3. If this in not possible, what is the cleanest possible way to support both versions temporarily?