|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
zooh Smarty n00b
Joined: 05 Oct 2004 Posts: 2 Location: Russia, Moscow
|
Posted: Tue Oct 05, 2004 11:36 am Post subject: Useful feature for config files?.. |
|
|
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 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 ). 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 |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Oct 05, 2004 2:03 pm Post subject: |
|
|
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 |
|
zooh Smarty n00b
Joined: 05 Oct 2004 Posts: 2 Location: Russia, Moscow
|
Posted: Tue Oct 05, 2004 2:28 pm Post subject: |
|
|
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
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 |
|
Back to top |
|
|
|
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
|