Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8387239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:09:35+00:00 2026-06-09T18:09:35+00:00

I am in the process of upgrading a PHP-based site from Smarty2 to Smarty3.

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:09:36+00:00Added an answer on June 9, 2026 at 6:09 pm

    I had not realized that the change I described in the question also works with version 2:

    {if $dynVal == $smarty.const.SOME_CONSTANT}dynamic content{/if}
    

    I’ll hold out to see what other answers come, as I’d still prefer to not have to change the templates if I don’t have to, but I think this is likely going to be the cleanest way to make the change. I was worried that I was going to have to do something like this:

    {if ($newSmarty && $dynVal == $smarty.const.SOME_CONSTANT) || (!newSmarty && 'dynVal' == SOME_CONSTANT) }dynamic content{/if}
    

    And nobody wants to maintain that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php based system working perfectly since 2006, which has a backend
I have started the process of upgrading my mvc projects from 2 to 3
I am upgrading my site from some old spaghetti coding to some nice, clean
I am in the process of upgrading the security level of my site. When
I have an application in PHP/MySQL. I am searching for an automated way upgrading
I have a process that uploads files via PHP but the resulting files end
I have an html input field, such as <form method=post action=process.php enctype=multipart/form-data> <div> <h3>Files:</h3>
I have tried upgrading from jQuery 1.2.6 to 1.4.1. A JSON query is now
I am compiling PHP and PostgreSQL myself. I have got things working fine. There
We are in the process of upgrading to WebSphere 7.0 on Windows 2008 R2.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.