Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Function declaration needed
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
U.Tews
Administrator


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

PostPosted: Thu Dec 31, 2009 5:54 pm    Post subject: Reply with quote

Ups I made an error when posting.

external declared template function must be called by

{call name=test}

Checking if the function name is valid is done at run time.



Besides that regardin your cases:

A:

{function} tags are processed at compile time. the {if} is a runtime tag.
So the template function gets always compiled. If you call the function in file 2 it gets alwas executed.
Anyway it would be more usefull o have the {if} in file2 around the call. Makes the whole thing more understandable.

B:

Will drop an error message at run time as the template function definition did not get loaded for x=2.

C:

Does work.
Back to top
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Thu Dec 31, 2009 6:15 pm    Post subject: Reply with quote

U.Tews wrote:
Ups I made an error when posting.

external declared template function must be called by

{call name=test}


Ok, so in all of my examples, I would have to change
{test} to
{call name=test}

in order for it to work.
Back to top
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Tue Jan 05, 2010 9:57 am    Post subject: Reply with quote

Just wanted to remark that perhaps if there was a standard place for template libraries like there was for plugins in php files, for that case, the dynamic call syntax might not be needed.

Like function.funcname.tpl

Maybe the file could be in the usual plugins dir(s).

Or it could always look in the same dir as the template, but then the file might be more easily renamed/erased, and it could only be used by templates in the same dir (without using the dynamic call syntax)

just throwing out ideas...
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Tue Jan 05, 2010 9:39 pm    Post subject: Reply with quote

The requirement of the dynamic call syntax has nothing to do where the files are located or how they are named.

It is required because of the way how the general flow of template and subtemplate handling works.

It would be difficult to change that for templaste functions and for example it could not work for variable filenames of the libraries. Much more trouble than benefit.
Back to top
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Tue Jan 05, 2010 10:41 pm    Post subject: Reply with quote

U.Tews wrote:
The requirement of the dynamic call syntax has nothing to do where the files are located or how they are named.

It is required because of the way how the general flow of template and subtemplate handling works.

It would be difficult to change that for templaste functions and for example it could not work for variable filenames of the libraries. Much more trouble than benefit.



i was thinking it was a requirement because of the difficulty of resolving a name to a specific function at compile time before the includes have been processed at run time.

If I didn't make it clear, the file would automatically be included without the need for {include}, just like a plugin function. That way, resolving the function name does not depend on any runtime conditions within templates or subtemplates etc. The file is either there at compile time or it's not.

If it's impossible or so difficult, why don't plugin functions in PHP need dynamic call syntax?


No big deal though... Just a thought. Smile
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Wed Jan 06, 2010 3:42 pm    Post subject: Reply with quote

Okay, I think now I got you. But that would similar to plugins require one file for each function.

Maybe something to consider for the future....
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3 All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
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