Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Accessing class constants

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
azabu
Smarty n00b


Joined: 24 Jul 2010
Posts: 1

PostPosted: Sat Jul 24, 2010 12:58 am    Post subject: Accessing class constants Reply with quote

There doesn't appear to be a way to access class constants from Smarty. E.g.
Code:
class Foo {
  const BAR = "baz";
}
echo Foo::BAR;

In Smarty I've had to make some minor modifications to get this to work. In the template I use the format:
Code:
{$smarty.const.Foo.BAR}

And the modifications run like so:
Code:
sysplugins/smarty_internal_compile_private_special_variable.php
            case 'const':
                if ($compiler->smarty->security && !$compiler->smarty->security_policy->allow_constants) {
                    $compiler->trigger_template_error("(secure mode) constants not permitted");
                    break;
                }
+                if(count($_index) == 3) {
+                    return "@".trim($_index[1], "'").'::'.trim($_index[2], "'");
+                }
                return '@' . trim($_index[1], "'");

It would be great if class constants could be accessed from within Smarty 3.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sat Jul 24, 2010 9:00 am    Post subject: Reply with quote

In Smarty3 static class access was addeded to the syntax. Just use Foo::BAR.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty 3 All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP