Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Can't get Smarty to register new plugin
Goto page 1, 2  Next
 
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 -> Installation and Setup
View previous topic :: View next topic  
Author Message
strafford
Smarty Rookie


Joined: 27 Jun 2018
Posts: 17

PostPosted: Mon Feb 04, 2019 7:01 pm    Post subject: Can't get Smarty to register new plugin Reply with quote

I must be missing some piece of the setup. I think Smarty is setup correctly as nothing comes up when using $tpl->testInstall() - all tests return 'OK'.

I show my plugin dir with getPluginsDir and it is ok: /usr/local/php7/lib/php/Smarty/plugins/

Trying to install smarty-gettext. Copied the files block.t.php and function.locale.php to the plugins dir as per the install instructions. Confirmed with is_file that the file block.t.php is there in the plugins dir.

But, when I try to register the plugin like this:
Code:
$tpl->registerPlugin('block','t','block_t');


I get this error:
Fatal error: Uncaught --> Smarty: Plugin 't' not callable <-- thrown in /usr/local/php7/lib/php/Smarty/sysplugins/smarty_internal_method_registerplugin.php on line 50
Back to top
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Tue Feb 05, 2019 2:39 am    Post subject: Reply with quote

I think the name of the callback argument needs to be the actual name of a function that PHP is already aware of.

The plugin block.t.php is probably parsed by PHP early enough, so the names of the functions in that file should then be known to PHP.

But looking at the contents of that file, I see the actual name of the function is smarty_block_t but your argument is block_t.
Back to top
View user's profile Send private message
strafford
Smarty Rookie


Joined: 27 Jun 2018
Posts: 17

PostPosted: Tue Feb 05, 2019 12:16 pm    Post subject: Reply with quote

I have tried all those combinations - with smarty_, with and without smarty_block, etc. When I change the registerPlugin code to this:
Code:
$tpl->registerPlugin('block','tzz','smarty_block_t');

I get the following error:
Fatal error: Uncaught --> Smarty: Plugin 't' not callable <-- thrown in /usr/local/php7/lib/php/Smarty/sysplugins/smarty_internal_method_registerplugin.php on line 50

I also tried one of the blocks that came with the smarty install - block.textformat.php and get the same results:
Code:
$tpl->registerPlugin('block','tx','smarty_block_textformat');

With the results:
Fatal error: Uncaught --> Smarty: Plugin 'tx' not callable <-- thrown in /usr/local/php7/lib/php/Smarty/sysplugins/smarty_internal_method_registerplugin.php on line 50
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Tue Feb 05, 2019 9:40 pm    Post subject: Reply with quote

If you correctly place your files in a directory loadable by Smarty's plugin system, you don't need to register anything.
This is further reinforced by the function names.

P.S.
Do NOT place anything into Smarty vendor dirs. Keep your custom code separate.
See Smarty::addPluginsDir.

P.P.S.
Furthermore, don't use gettext, as it depends on setlocale(3) call, which changes language for ENTIRE PROCESS, not just current thread.
Back to top
View user's profile Send private message
strafford
Smarty Rookie


Joined: 27 Jun 2018
Posts: 17

PostPosted: Wed Feb 06, 2019 7:13 pm    Post subject: Reply with quote

AnrDaemon wrote:
If you correctly place your files in a directory loadable by Smarty's plugin system, you don't need to register anything.
This is further reinforced by the function names.


But it should still function, correct? - right now it stops smarty from working.
Back to top
View user's profile Send private message
strafford
Smarty Rookie


Joined: 27 Jun 2018
Posts: 17

PostPosted: Wed Feb 06, 2019 8:57 pm    Post subject: Reply with quote

I have created a new directory for custom plugins as suggested. Still getting the error that it is not callable. When I create a test function like this it works:

Code:
function Zsmarty_block_t ($params, $content, $smarty, &$repeat, $template)
{
  if (isset($content)) {
    return "blah";
  }
}


try{
  $tpl->registerPlugin('block','t','Zsmarty_block_t');
} catch (Exception $e) {
  echo "exception: ".$e->getMessage();
}


This is taken from here.
Back to top
View user's profile Send private message
strafford
Smarty Rookie


Joined: 27 Jun 2018
Posts: 17

PostPosted: Thu Feb 07, 2019 2:31 pm    Post subject: Reply with quote

I have also noticed that the documentation for block functions is not consitant. When looking here at registerPlugin there are 5 parameters for a block function like this:
Code:
function do_translation ($params, $content, $smarty, &$repeat, $template)


But when you look here at block functions there are only 4 parameters for a block function like this:
Code:
function smarty_block_translate($params, $content, Smarty_Internal_Template $template, &$repeat)


Does anyone know which is correct?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu Feb 07, 2019 3:00 pm    Post subject: Reply with quote

Please provide a step by step instructions.
Best if you could clone https://github.com/AnrDaemon/test-001 , create a new branch and reproduce your issue within it.

P.S.
https://www.smarty.net/docs/en/plugins.block.functions.tpl is correct.
Back to top
View user's profile Send private message
strafford
Smarty Rookie


Joined: 27 Jun 2018
Posts: 17

PostPosted: Thu Feb 07, 2019 3:39 pm    Post subject: Reply with quote

Thanks AnrDaemon. Not sure if I am doing this correctly, but I tried to push the new branch like this:

Code:
git push https://github.com/AnrDaemon/test-001.git testblockplugin


Got an error:
Code:
remote: Permission to AnrDaemon/test-001.git denied to <myusername>.
fatal: unable to access 'https://github.com/AnrDaemon/test-001.git/': The requested URL returned error: 403
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu Feb 07, 2019 7:30 pm    Post subject: Reply with quote

If you don't have GitHub account, just
Code:
tar caf ../example.tar.gz --exclude=.git --exclude-ignore=.gitignore -- .
the directory and upload it somewhere.
If you do have one,
1. Fork the repository on github.
2. Clone your fork.
3. Create a branch from master.
4. Run `composer install`
5. Reproduce your issue and commit changes.
6. Push to your fork.
7. Post the link.
Back to top
View user's profile Send private message
strafford
Smarty Rookie


Joined: 27 Jun 2018
Posts: 17

PostPosted: Thu Feb 07, 2019 7:55 pm    Post subject: Reply with quote

I did create a git account. Don't have composer but not sure it would be needed in this case to replicate.

I have uploaded the files here: http://www.filedropper.com/testblockplugintar

This is what I did do w/ git:
1. git clone https://github.com/AnrDaemon/test-001.git
2. cd test-001/
3. git checkout -b testblockplugin
4. copy in code required
5. git add .
6. git push https://github.com/AnrDaemon/test-001.git testblockplugin

Maybe I am not understanding what is required here....sorry.
Back to top
View user's profile Send private message
strafford
Smarty Rookie


Joined: 27 Jun 2018
Posts: 17

PostPosted: Thu Feb 07, 2019 8:20 pm    Post subject: Reply with quote

FYI testing Smarty 3.1.33 with PHP 5.6.40
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu Feb 07, 2019 9:02 pm    Post subject: Reply with quote

I tweaked master branch a bit, added a demo testcase and a packaging script for those without their own git repos.

strafford wrote:
FYI testing Smarty 3.1.33 with PHP 5.6.40

That shouldn't make a big difference.
Back to top
View user's profile Send private message
strafford
Smarty Rookie


Joined: 27 Jun 2018
Posts: 17

PostPosted: Fri Feb 08, 2019 2:02 pm    Post subject: Reply with quote

Did you want me to do that or are the files at http://www.filedropper.com/testblockplugintar enough?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sat Feb 09, 2019 1:38 am    Post subject: Reply with quote

Sorry, the archiver says the file is incomplete.
Back to top
View user's profile Send private message
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 -> Installation and Setup All times are GMT
Goto page 1, 2  Next
Page 1 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