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 functions within other smarty functions

 
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 -> General
View previous topic :: View next topic  
Author Message
cablehead
Smarty Rookie


Joined: 09 Jul 2003
Posts: 23

PostPosted: Tue Jul 22, 2003 10:52 am    Post subject: smarty functions within other smarty functions Reply with quote

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 Sad .. 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
View user's profile Send private message Send e-mail
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Jul 22, 2003 12:16 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
cablehead
Smarty Rookie


Joined: 09 Jul 2003
Posts: 23

PostPosted: Tue Jul 22, 2003 12:48 pm    Post subject: Reply with quote

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 Wink
Back to top
View user's profile Send private message Send e-mail
andre
Smarty Pro


Joined: 23 Apr 2003
Posts: 164
Location: Karlsruhe, Germany

PostPosted: Wed Jul 23, 2003 7:33 am    Post subject: Reply with quote

I would create a custom resource: http://smarty.php.net/manual/en/template.resources.php

Then you can write something like {include file="locate:tpl.main.html"}.
Back to top
View user's profile Send private message
boots
Administrator


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

PostPosted: Wed Jul 23, 2003 7:53 am    Post subject: Reply with quote

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


Joined: 09 Jul 2003
Posts: 23

PostPosted: Wed Jul 23, 2003 9:19 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
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 -> General 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