View previous topic :: View next topic |
Author |
Message |
strafford Smarty Rookie
Joined: 27 Jun 2018 Posts: 17
|
Posted: Mon Feb 04, 2019 7:01 pm Post subject: Can't get Smarty to register new plugin |
|
|
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 |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Tue Feb 05, 2019 2:39 am Post subject: |
|
|
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 |
|
strafford Smarty Rookie
Joined: 27 Jun 2018 Posts: 17
|
Posted: Tue Feb 05, 2019 12:16 pm Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Feb 05, 2019 9:40 pm Post subject: |
|
|
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 |
|
strafford Smarty Rookie
Joined: 27 Jun 2018 Posts: 17
|
Posted: Wed Feb 06, 2019 7:13 pm Post subject: |
|
|
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 |
|
strafford Smarty Rookie
Joined: 27 Jun 2018 Posts: 17
|
Posted: Wed Feb 06, 2019 8:57 pm Post subject: |
|
|
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 |
|
strafford Smarty Rookie
Joined: 27 Jun 2018 Posts: 17
|
Posted: Thu Feb 07, 2019 2:31 pm Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
|
Back to top |
|
strafford Smarty Rookie
Joined: 27 Jun 2018 Posts: 17
|
Posted: Thu Feb 07, 2019 3:39 pm Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu Feb 07, 2019 7:30 pm Post subject: |
|
|
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 |
|
strafford Smarty Rookie
Joined: 27 Jun 2018 Posts: 17
|
|
Back to top |
|
strafford Smarty Rookie
Joined: 27 Jun 2018 Posts: 17
|
Posted: Thu Feb 07, 2019 8:20 pm Post subject: |
|
|
FYI testing Smarty 3.1.33 with PHP 5.6.40 |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu Feb 07, 2019 9:02 pm Post subject: |
|
|
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 |
|
strafford Smarty Rookie
Joined: 27 Jun 2018 Posts: 17
|
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sat Feb 09, 2019 1:38 am Post subject: |
|
|
Sorry, the archiver says the file is incomplete. |
|
Back to top |
|
|