View previous topic :: View next topic |
Author |
Message |
webtweakers Smarty Rookie
Joined: 20 Apr 2009 Posts: 7
|
Posted: Wed Apr 29, 2009 7:35 am Post subject: |
|
|
douglassdavis wrote: | it would be nice to be able to get the directory of the current template from within the template.
I ask because i have a template (template A) that can include another template (template B) from another directory, but it's configurable so it could come from ANY directory.
Since template B can't find out what directory it is in, it can't do an include of template C in the same directory. An absolute path is needed, and without knowing the its own directory, I don't know how that's supposed to happen. |
Sounds like you need to rethink your application logic. You've created something overly complicated and now ask Smarty to fix it. |
|
Back to top |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Wed Apr 29, 2009 5:20 pm Post subject: |
|
|
webtweakers wrote: | douglassdavis wrote: | it would be nice to be able to get the directory of the current template from within the template.
I ask because i have a template (template A) that can include another template (template B) from another directory, but it's configurable so it could come from ANY directory.
Since template B can't find out what directory it is in, it can't do an include of template C in the same directory. An absolute path is needed, and without knowing the its own directory, I don't know how that's supposed to happen. |
Sounds like you need to rethink your application logic. You've created something overly complicated and now ask Smarty to fix it. |
Just because you don't understand something, or you find things complicated you should not judge others by the limitations of your own capabilities.
I would be happy to provide for you an explanation as far as why it is implemented that way, if you think you can contribute something to the conversation. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Apr 29, 2009 8:02 pm Post subject: |
|
|
Typically you keep track of your templates relative to the template_dir root. So anytime you include a template, you would be doing something like:
Code: | {include file="/$theme/myfoo.tpl"} |
Which is always relative to template root. If you wanted, you could pass local vars when including a template and try to keep track of the current template subdir. You could also make your own template resource and make it as complex as you'd like. |
|
Back to top |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Wed Apr 29, 2009 10:54 pm Post subject: |
|
|
mohrt wrote: | Typically you keep track of your templates relative to the template_dir root. So anytime you include a template, you would be doing something like:
Code: | {include file="/$theme/myfoo.tpl"} |
Which is always relative to template root. If you wanted, you could pass local vars when including a template and try to keep track of the current template subdir. You could also make your own template resource and make it as complex as you'd like. |
ok, thanks.
I have passed in a path var. If the template was able to find its own dir, that would make it more self-sufficient, but passing in a path var works too. |
|
Back to top |
|
tonald Smarty Rookie
Joined: 05 May 2009 Posts: 8
|
Posted: Tue May 05, 2009 5:25 am Post subject: |
|
|
It is cool!!!! |
|
Back to top |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Tue Jun 09, 2009 10:06 pm Post subject: |
|
|
mohrt wrote: | Typically you keep track of your templates relative to the template_dir root. So anytime you include a template, you would be doing something like:
Code: | {include file="/$theme/myfoo.tpl"} |
Which is always relative to template root. If you wanted, you could pass local vars when including a template and try to keep track of the current template subdir. You could also make your own template resource and make it as complex as you'd like. |
Thinking about this, I still think that it would be good for a template to be able to figure out what directory it is in.
For example, template libraries. Say you have a group of templates in a library directory sitting waiting to be included, and they in turn include other templates in the library directory.
So, using the "keeping track using a variable" method, those library templates would have to rely on whoever is using them to tell them where they are via some pre-agreed upon var, rather than just being able to figure it out by themselves and be more self sufficient.
I suppose I could make a template resource, but this seems like such a simple, useful idea. It doesn't seem complicated to me. How about adding a built in resource of "current_directory:" or something like that.
If not, how would I create one? What can I use in the smarty object to tell me the path to the template being executed? Is there anything in smarty 2 as well?
I have template libraries, but as of right now, they just don't include anything else.
Last edited by douglassdavis on Thu Jun 11, 2009 10:46 am; edited 1 time in total |
|
Back to top |
|
FractalizeR Smarty Rookie
Joined: 01 Nov 2003 Posts: 16
|
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Jun 10, 2009 2:33 pm Post subject: |
|
|
Changed. |
|
Back to top |
|
yankee Smarty Rookie
Joined: 02 Mar 2009 Posts: 31
|
Posted: Mon Jun 15, 2009 9:28 pm Post subject: |
|
|
mohrt wrote: | The only way feasible around it would create more runtime processing. {$foo.bar} could get compiled into something like $smarty->fetch_value('foo','bar'), and the runtime would check if $foo is an object or array, and get foo from either or. As you can see, this creates an extra method call on each variable iteration. Not good.
I think we can live with $foo.bar and $foo->bar. Although this may not be perfect for the designer, it will keep the developer's debug frustrations to a minimum. |
I agree. Additionally I'd like to add that sometimes it is very important to distinguish beetween array access and object access if the objects implements the array access interface.
If your really dislike php's object access operator, implement array access in your classes. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Jun 18, 2009 7:04 pm Post subject: |
|
|
The special variable $smarty.current_dir does now return the dirname of the current template. |
|
Back to top |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Thu Jun 18, 2009 7:09 pm Post subject: |
|
|
U.Tews wrote: | The special variable $smarty.current_dir does now return the dirname of the current template. |
Yes!! |
|
Back to top |
|
goper Smarty Rookie
Joined: 24 Jul 2007 Posts: 5
|
Posted: Thu Nov 05, 2009 10:30 am Post subject: |
|
|
And what about config files?
It would be great to not have one global config array, and assign only what you want, to templates you want.
Also would be great to have config files not only for templates.
In Smarty 2 if i load, different section...
$smarty->config_load('russian.conf','pdf_section');
$lang_array = $smarty->get_config_vars();
I will lose previously loaded config, and would have load it once again.
Also since Smarty class object, 99% times is unique, would be nice have feature like
$smarty = Smarty::getInstance();
PS:Yeah i know i can easy write singleton wrapper myself, but it would be nice to have this feature by default
PPS:If any of these features already implemented, please don't say just 'RTFM', say at least a page number )
PPPS: Thank you dear development team, Smarty 3 is great! ([] array definition is great, PHP should make the same, and now i have a long awaited variable scope) |
|
Back to top |
|
mitchenall Smarty Pro
Joined: 27 Feb 2004 Posts: 107 Location: London, UK
|
Posted: Thu Nov 05, 2009 5:01 pm Post subject: |
|
|
goper wrote: |
$smarty = Smarty::getInstance();
PS:Yeah i know i can easy write singleton wrapper myself, but it would be nice to have this feature by default |
Please no!
As you said, you could easily write your own wrapper. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Nov 05, 2009 5:09 pm Post subject: |
|
|
This was discussed already earlier.
For good reasons the final decission was NO. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Nov 05, 2009 6:25 pm Post subject: |
|
|
Config files can now be loaded from the script on data and template objects.
$tpl = $smarty->createTemplate('mytpl.tpl'); // create template object
$tpl->config_load('my.conf'); // load config file |
|
Back to top |
|
|