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

Implementing a Smarty Plugin

 
Post new topic   Reply to topic    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
sandeepshinde
Smarty Rookie


Joined: 07 Jul 2004
Posts: 13

PostPosted: Wed Jul 07, 2004 7:09 am    Post subject: Implementing a Smarty Plugin Reply with quote

Hi there
I am new to smarty i have written a simple plugin for smarty
but i am not able to use it i.e actually add it like (html_options)


plz help me.
Back to top
View user's profile Send private message
tk
Smarty Regular


Joined: 31 Oct 2003
Posts: 49
Location: London, UK

PostPosted: Wed Jul 07, 2004 7:28 am    Post subject: Reply with quote

Yes... and there's a party you're invited to too ;)



Regards,

tk


PS: Yes my answer is stupid.. but it was the best I could offer with the amazing amount of info you provided in your post.
_________________
Certified Code Junkie(tM)
Copyleft (L) two thousand and now, tk
Back to top
View user's profile Send private message Visit poster's website
sandeepshinde
Smarty Rookie


Joined: 07 Jul 2004
Posts: 13

PostPosted: Wed Jul 07, 2004 8:28 am    Post subject: Help............... Reply with quote

Plz Dont give confusing answers plz help me out i am in serious problem
Back to top
View user's profile Send private message
boots
Administrator


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

PostPosted: Wed Jul 07, 2004 9:14 am    Post subject: Reply with quote

Please read the appropriate manual section, http://smarty.php.net/manual/en/plugins.php and let us know what your specific problems are. Show us what you have done, explain what you thought should happen and tell us where you are stuck. Otherwise, how can one help?
Back to top
View user's profile Send private message
sandeepshinde
Smarty Rookie


Joined: 07 Jul 2004
Posts: 13

PostPosted: Wed Jul 07, 2004 9:48 am    Post subject: Reply with quote

i Have written the following code
[php:1:06981e6ced]<?php
function smarty_function_array_counter($params, &$smarty)
{
$array_count=0;

$print_result = true;

(extract($params));

settype($input_array, 'array');
$array_count = count($input_array);

if($print_result)
print $array_count;
else
return $array_count;

}
?>[/php:1:06981e6ced]


and save the file as function.array_count.php in the plugins dir
now i am stuck that where should i place the alias name for the function
so it gets loaded by default when smarty starts like other function (html_options)
Back to top
View user's profile Send private message
boots
Administrator


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

PostPosted: Wed Jul 07, 2004 9:59 am    Post subject: Reply with quote

Actually, Smarty doesn't load any plugins by default (you have to explicitly load them if you want that sort of behavior). Instead, Smarty (cleverly) only loads plugins on demand. So, if you have placed that file in your plugin directory then all you need to do in your template is actually use your plugin (it will be called array_counter in this case) and Smarty will automatically load it for you. eg:
Code:
{array_count input_array=$arr print_result=true}


You may be interested to know that Smarty can (in its default settings) use PHP functions as modifiers. Thus, you need not such a plugin but instead can use the following:
Code:
{$arr|@count}


The '@' tells Smarty to pass $arr as an array to the count function. You can also use PHP function in if clauses, eg:
Code:
{if count($arr) > 0}
Back to top
View user's profile Send private message
sandeepshinde
Smarty Rookie


Joined: 07 Jul 2004
Posts: 13

PostPosted: Wed Jul 07, 2004 11:50 am    Post subject: Thanks Reply with quote

That realy helped me thnks a lot Very Happy
Back to top
View user's profile Send private message
tk
Smarty Regular


Joined: 31 Oct 2003
Posts: 49
Location: London, UK

PostPosted: Wed Jul 07, 2004 3:29 pm    Post subject: Re: Help............... Reply with quote

sandeepshinde wrote:
Plz Dont give confusing answers plz help me out i am in serious problem



You're kidding me right!?

In future then, I _strongly_ suggest you learn how to ask a question _properly_ in a manner in which warrants an answer. You're lucky I even wasted my time writing that reply.



Regards,

tk
_________________
Certified Code Junkie(tM)
Copyleft (L) two thousand and now, tk
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


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

PostPosted: Wed Jul 07, 2004 3:44 pm    Post subject: Reply with quote

it's true--I would have ignored this thread if not for tk's humour. Also, it would have been nice if, instead of denigrating tk's post, you actually posted some info in response instead of waiting until I explicitly asked for it.

Oh yeah, that "plz" language and "serious problem" stuff don't work for most people either. Please remember that we are all volounteers here when asking your questions and we'll try not to kick your ass if you do a good job of that Smile

Cheers all!
Back to top
View user's profile Send private message
tk
Smarty Regular


Joined: 31 Oct 2003
Posts: 49
Location: London, UK

PostPosted: Wed Jul 07, 2004 6:43 pm    Post subject: Reply with quote

I used to get the same when I worked as a mechanic (my original trade).. people would come in and say "my car don't start"... "ok, under what conditions?".. "when I get in.. it don't start" yeah... thanks =)

We had one woman come into a garage I worked in once... she said her car was "making noises". We took it out for a test drive.. I turned on the radio and asked if she could hear it still... "no, I can't" she replied. I killed the radio and she said "ahh, there it is again". Had I seriously followed up this "silly line of investigation".. I would have ended up selling her a head unit rather than fixing the problem under the bonnet.. heh.

It amuses me when people assume you're psychic and then get all funny when you don't respond in the manner in which they want / demand.. or the ones that prepend subject lines with !!!!!!URGENT!!!!!!!. If it's that urgent... RTFM!!!

I can't code everything.. but can offer some help with some things.. but seems some expect help _and_ expect you to know what's rolling around between their ears (often just air) [sigh] just to fix their issue.



Regards,

tk
_________________
Certified Code Junkie(tM)
Copyleft (L) two thousand and now, tk
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Plugins 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