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 constants in .tpl

 
Post new topic   Reply to topic    Smarty Forum Index -> Documentation
View previous topic :: View next topic  
Author Message
pedrotester
Smarty Regular


Joined: 06 Jun 2019
Posts: 40

PostPosted: Sun May 23, 2021 12:44 pm    Post subject: Accessing constants in .tpl Reply with quote

https://www.smarty.net/docs/en/language.variables.smarty.tpl#language.variables.smarty.const

We can also access constants simply like this {MY_CONSTANT}

I think it wasn't the case in early smarty v3 but now it works fine. Maybe add it to the page?



PS: after reading the warning, i don't quite see why I shouldn't directly use the constant in the TPL and instead assign a variable for it, does seem very redundant and useless
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1755

PostPosted: Sun May 30, 2021 8:09 am    Post subject: Reply with quote

Many people think that direct access to constants was an oversight in design. Way too easy to have a conflict with template functions/blocks.
Back to top
View user's profile Send private message
pedrotester
Smarty Regular


Joined: 06 Jun 2019
Posts: 40

PostPosted: Mon May 31, 2021 2:17 pm    Post subject: Reply with quote

AnrDaemon wrote:
Way too easy to have a conflict with template functions/blocks.


Do you have an example of such a conflict, please?
Maybe I should switch back to {$smarty.const.MY_CONST_VAL}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Documentation 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