|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
yr4ik Smarty Rookie
Joined: 06 Oct 2014 Posts: 15
|
Posted: Wed Mar 10, 2021 11:50 pm Post subject: Bug compile blocks with DefaultPluginHandler |
|
|
After compile tpl - we have wrong callback in compiled file.
PHP:
Code: | <?php
include_once('smarty-3.1.39/libs/Smarty.class.php');
class My_Smarty_Plugin_Class {
public static function test_modifier($var)
{
return 'work modifier';
}
public static function translate($params, $content, $smarty, &$repeat)
{
if($repeat)
return false;
return 'work block';
}
}
function smarty_plugin_handler($name, $type, $template, &$callback, &$script, &$cacheabl)
{
if(in_array($type, ['block', 'modifier']))
{
$callback = array('My_Smarty_Plugin_Class', $name);
return true;
}
return false;
}
$smarty = new Smarty();
$smarty->compile_dir = dirname(__FILE__);
$smarty->registerDefaultPluginHandler('smarty_plugin_handler');
echo $smarty->fetch('test.tpl'); |
TPL:
Code: | <h1>test 1:<h1>
{'99'|test_modifier}
<h1>test 2:<h1>
{translate lang="br"}Hello, world!{/translate} |
Result in compilled file:
Code: | <h1>test 1:<h1>
<?php echo My_Smarty_Plugin_Class::test_modifier('99');?>
<h1>test 2:<h1>
<?php
..............
echo translate::translate(array('lang'=>"br"), null, $_smarty_tpl, $_block_repeat); |
callback: translate::translate should have been My_Smarty_Plugin_Class::translate
Example in archive https://drive.google.com/file/d/1SVb3L9vzYx3U-k9DomTtiTTNYDWo11w3/view?usp=sharing |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Mar 17, 2021 12:26 pm Post subject: |
|
|
Which means, it knows the tag "{translate}" |
|
Back to top |
|
yr4ik Smarty Rookie
Joined: 06 Oct 2014 Posts: 15
|
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
|
Back to top |
|
yr4ik Smarty Rookie
Joined: 06 Oct 2014 Posts: 15
|
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Apr 20, 2021 4:12 pm Post subject: |
|
|
I'll test it once I have some free time. |
|
Back to top |
|
yr4ik Smarty Rookie
Joined: 06 Oct 2014 Posts: 15
|
Posted: Tue Apr 20, 2021 8:48 pm Post subject: |
|
|
see compiled file. There will be an error in callback |
|
Back to top |
|
yr4ik Smarty Rookie
Joined: 06 Oct 2014 Posts: 15
|
Posted: Fri Aug 13, 2021 11:23 am Post subject: |
|
|
5 months have passed. Delete test files? |
|
Back to top |
|
|
|
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
|