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

Useful feature for config files?..

 
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 -> Feature Requests
View previous topic :: View next topic  
Author Message
zooh
Smarty n00b


Joined: 05 Oct 2004
Posts: 2
Location: Russia, Moscow

PostPosted: Tue Oct 05, 2004 11:36 am    Post subject: Useful feature for config files?.. Reply with quote

As for now, I can use constants only in Smarty config files, and here is the problem.

Let's imagine, that I'd like to have a table with two columns in my application. But I want to have an ability to change width of left column via config, and I want them not to depend on total width of table.

Ok, here's the config:

Code:

total_width = "950"
left_column = "200"
right_column = "750"


What the... ? But right column is always total_width - left_column! And this is a simple sample, real markup can be much more complicated. So, to change one parameter, I'll have to change dozens of related ones.

Ok, let's try to use the power of Smarty to solve this problem:

Code:

{assign var="right_column" value=$smarty.config.total_width-$smarty.config.left_column}


But I might need this value in dozens of different templates! I'd like to write this code once and use it wherever I need. Ok, let's move this code into separate file and use {include}... Stop! All the variables defined in included file are visible only from inside of that file... So they are useless to me in my case Sad Of course, I could write this code in the top-level template, but what if I use several different top-level templates?

So, here's the problem. Smarty needs some possibility either to allow some calculations ({math} - like, for example) inside config file, or some possibility to make variables from included files globally available (imagine problems with caching, heh Smile ). Or it may introduce some function like {assign_config var=... value=...}. Or it may introduce some function like {include_local file=...}, so that it just inserted content of the included file into current template just before compiling. Or, maybe, something else?.. What do you think?
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Tue Oct 05, 2004 2:03 pm    Post subject: Reply with quote

Interesting and a good synopsis.

In the past, I have written patches for both templated config files and includes with global (or bubble-up, actually) scopes (both are somewhere here on the forums but they have not been updated in a very long time). I like your idea of inlining includes but there is a problem with all of these methods in that they make assumptions as to what the content of the included files will be like.

Maybe what you need is to keep things exactly as they are and instead write templates that target config files so that you can use Smarty template features (like math) but regenerate them as static text as required. I'm a believer that sometimes it is easier and makes more sense to alter the work-flow than it is to alter the codebase.
Back to top
View user's profile Send private message
zooh
Smarty n00b


Joined: 05 Oct 2004
Posts: 2
Location: Russia, Moscow

PostPosted: Tue Oct 05, 2004 2:28 pm    Post subject: Reply with quote

boots wrote:
I like your idea of inlining includes but there is a problem with all of these methods in that they make assumptions as to what the content of the included files will be like.


I didn't understand you. There's no difference what is in inline template; it should work simply as C++ #include directive.

boots wrote:
Maybe what you need is to keep things exactly as they are... ....regenerate them as static text as required.


Well, it's an obvious solution, but I'm sure that it's possible to teach Smarty to automate this activity Smile

boots wrote:
I'm a believer that sometimes it is easier and makes more sense to alter the work-flow than it is to alter the codebase.

Well, it works while I don't need scripts that generate scripts that generate configs Wink
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 -> Feature Requests 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