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

Can't find plugin in directory

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


Joined: 12 Dec 2005
Posts: 7

PostPosted: Wed Jul 29, 2020 6:22 pm    Post subject: Can't find plugin in directory Reply with quote

Hi - I'm sure this has been asked before and I'm sure there's a simple answer but I can't find it.

I've created a new plugin function called email_setup. The filename is function.email_setup.php, located in /home/manager/plugins. Here's the code:
Code:
function smarty_function_email_setup($params, $template='')
{
   if (is_array($params['data'])) {
      $result = "Email setup called: {$params['data']['temp']}";
   }
   return $result;
}

The problem is not with the code; calling it as a standalone function works. I've also created a file function.eightball.php, copied directly from the example in the Smarty docs, and put it in the same directory.

Using {eightball} in a template works as expected. But using
Code:
{$mydata.email='email'}
{email_setup($mydata)}

throws an error:
Code:
Fatal error: Uncaught --> Smarty Compiler: Syntax error in template "eval:<div class="report"> <h1>{$report_option..." on line 8 "{email_setup($mydata)}" unknown function "email_setup" <-- thrown in /home/espritg/manager/lib/smarty-3.1.29/libs/sysplugins/smarty_internal_templatecompilerbase.php on line 8

So the question is, why is {eightball} found and executed, and {email_setup}, in the same directory and with identical permissions, not even found?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1646

PostPosted: Thu Jul 30, 2020 11:17 am    Post subject: Reply with quote

Code:
{email_setup data=$mydata}


But you are doing it wrong. Don't use templates for your business logic.
Back to top
View user's profile Send private message
Stephanie
Smarty Rookie


Joined: 12 Dec 2005
Posts: 7

PostPosted: Thu Jul 30, 2020 4:28 pm    Post subject: Reply with quote

I understand that templates are supposed to help separate logic from display, but in my case I do have a good reason for doing this, and that was not the point of my question.
To reiterate: why is one function (eightball) found and executed but the other one (email_setup) throws a "not found" error? Both live in the same plugins directory.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1646

PostPosted: Thu Jul 30, 2020 9:53 pm    Post subject: Reply with quote

Your Smarty version is grossly outdated to begin with.
And to the point of your problem, double check the naming.

If you are still convinced everything is all right, try replicating you issue using this testbed: https://github.com/AnrDaemon/test-001

Link the repo with reproduction case, please.
Back to top
View user's profile Send private message
Stephanie
Smarty Rookie


Joined: 12 Dec 2005
Posts: 7

PostPosted: Mon Aug 03, 2020 4:48 am    Post subject: Reply with quote

So I can now use my email_setup function (yes, I know, logic vs. display and all that, but that's not the point).
However I can't call it like
Code:
{email_setup($parameters)}
(parenthesised style); I get an unknown function error.
If I use
Code:
{email_setup address='me@example.com' name='My Name'}
- i.e. the non-parenthesised style - it works.
Yet I have another function defined in the same plugins directory which works just fine with the parenthesised-style call:
Code:
{get_transactions(21064372)}

Where else can I look for clues?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1646

PostPosted: Mon Aug 03, 2020 8:57 am    Post subject: Reply with quote

In documentation.
https://www.smarty.net/docs/en/language.syntax.functions.tpl
Back to top
View user's profile Send private message
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