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

Smarty 3.0 Alpha 1: Proof of Concept
Goto page Previous  1, 2, 3, 4, 5, 6, 7  Next
 
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
webtweakers
Smarty Rookie


Joined: 20 Apr 2009
Posts: 7

PostPosted: Wed Apr 29, 2009 7:35 am    Post subject: Reply with quote

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
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Wed Apr 29, 2009 5:20 pm    Post subject: Reply with quote

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. Wink

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Apr 29, 2009 8:02 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Wed Apr 29, 2009 10:54 pm    Post subject: Reply with quote

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
View user's profile Send private message
tonald
Smarty Rookie


Joined: 05 May 2009
Posts: 8

PostPosted: Tue May 05, 2009 5:25 am    Post subject: Reply with quote

It is cool!!!!
Back to top
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Tue Jun 09, 2009 10:06 pm    Post subject: Reply with quote

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
View user's profile Send private message
FractalizeR
Smarty Rookie


Joined: 01 Nov 2003
Posts: 16

PostPosted: Wed Jun 10, 2009 1:20 pm    Post subject: Reply with quote

http://smarty-php.googlecode.com/svn/branches/Smarty3Alpha/README - this file is absent. First post in the thread should be corrected to
http://smarty-php.googlecode.com/svn/branches/Smarty3Alpha/distribution/README
_________________
Things are changing,
But nothing changes,
And still there are changes
Back to top
View user's profile Send private message Send e-mail
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Jun 10, 2009 2:33 pm    Post subject: Reply with quote

FractalizeR wrote:
http://smarty-php.googlecode.com/svn/branches/Smarty3Alpha/README - this file is absent. First post in the thread should be corrected to
http://smarty-php.googlecode.com/svn/branches/Smarty3Alpha/distribution/README


Changed.
Back to top
View user's profile Send private message Visit poster's website
yankee
Smarty Rookie


Joined: 02 Mar 2009
Posts: 31

PostPosted: Mon Jun 15, 2009 9:28 pm    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Thu Jun 18, 2009 7:04 pm    Post subject: Reply with quote

The special variable $smarty.current_dir does now return the dirname of the current template.
Back to top
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Thu Jun 18, 2009 7:09 pm    Post subject: Reply with quote

U.Tews wrote:
The special variable $smarty.current_dir does now return the dirname of the current template.



Yes!! Smile
Back to top
View user's profile Send private message
goper
Smarty Rookie


Joined: 24 Jul 2007
Posts: 5

PostPosted: Thu Nov 05, 2009 10:30 am    Post subject: Reply with quote

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
View user's profile Send private message
mitchenall
Smarty Pro


Joined: 27 Feb 2004
Posts: 107
Location: London, UK

PostPosted: Thu Nov 05, 2009 5:01 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
U.Tews
Administrator


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

PostPosted: Thu Nov 05, 2009 5:09 pm    Post subject: Reply with quote

This was discussed already earlier.

For good reasons the final decission was NO.
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Thu Nov 05, 2009 6:25 pm    Post subject: Reply with quote

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
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
Goto page Previous  1, 2, 3, 4, 5, 6, 7  Next
Page 6 of 7

 
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