|
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 |
cablehead Smarty Rookie
Joined: 09 Jul 2003 Posts: 23
|
Posted: Tue Jul 22, 2003 10:52 am Post subject: smarty functions within other smarty functions |
|
|
Hi all,
I've written a smarty function 'locate' which goes and finds the most appropiate version of a file to use given the user's context. ie you could have a global template and potentially a user customised template.
The idea is to go:
{include file={locate file="tpl.main.html"}}
If the user has customised the global template, it will pick up their version, otherwise it will pick up the global version. The above doesn't work though .. is this because you're not allowed to have functions within functions in smarty?
The following does work:
{capture name=tplmain}{locate file="tpl.main.html"}{/capture}
{include file=$smarty.capture.tplmain}
But it's a bit long winded.
Any help is greatly appreciated,
Andy. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Tue Jul 22, 2003 12:16 pm Post subject: |
|
|
maybe you can restructure your smarty_function_locate() to become smarty_modifier_locate(). then you can call it:
{include file="tpl.main.html"|locate} |
|
Back to top |
|
cablehead Smarty Rookie
Joined: 09 Jul 2003 Posts: 23
|
Posted: Tue Jul 22, 2003 12:48 pm Post subject: |
|
|
cheers once again messju !
That does the job nicely. I didn't know you could use modifiers on hard coded text like that.
Smarty even let me keep the locate function along side the locate modifier so it's possible to write:
{include file="tpl.main.html"|locate}
as you say + things like
<img src="{locate file=img1.jpg}">
in addition to
<img src="{"img1.jpg"|locate}">
I'm starting to love smarty |
|
Back to top |
|
andre Smarty Pro
Joined: 23 Apr 2003 Posts: 164 Location: Karlsruhe, Germany
|
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Jul 23, 2003 7:53 am Post subject: |
|
|
Interesting.
I'd have to agree with andre that the resource facility is the most appropriate for template loading schemes.
The modifier does seem an elegant way to handle the HTML parameters, though; however, assuming that the HTML paths (unlike the template paths) can't be "overridden" and are therefore static, I think that simple config vars are most appropriate if for no other reason that, on average, they should outperform modifiers. |
|
Back to top |
|
cablehead Smarty Rookie
Joined: 09 Jul 2003 Posts: 23
|
Posted: Wed Jul 23, 2003 9:19 am Post subject: |
|
|
Thanks for the tip Andre!
I'll give that way a try as well.
I'll still need the locate function though to use with things like images and ccs files etc .. ?
Heya boot - the idea I'm trying for is to have a number of levels of fall back for find the right file to use. For instance a site has several sections, different types of user and then the actual user. Templates, ccs files and images can be place at any of these levels.
The locate function checks to see if first the user has a customized version, then if the type of user has a customized version, then if the section has a customised version and then finally falls back on the global version. It actually goes prowling around the filesystem to see what it can find. So if you place a css file in a type of users area, instantly all users of that type will see the effects of the different style.
I don't think the hard coded nature of config files would work in this scenario. |
|
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
|