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

Bug compile blocks with DefaultPluginHandler

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


Joined: 06 Oct 2014
Posts: 14

PostPosted: Wed Mar 10, 2021 11:50 pm    Post subject: Bug compile blocks with DefaultPluginHandler Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1728

PostPosted: Wed Mar 17, 2021 12:26 pm    Post subject: Reply with quote

Which means, it knows the tag "{translate}"
Back to top
View user's profile Send private message
yr4ik
Smarty Rookie


Joined: 06 Oct 2014
Posts: 14

PostPosted: Wed Mar 24, 2021 10:54 pm    Post subject: Reply with quote

not. The tag can be anything. Callback error during compilation.
http://joxi.ru/Grqlp7VcGDa1PA?d=1
Check example
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1728

PostPosted: Thu Mar 25, 2021 2:17 pm    Post subject: Reply with quote

Please fork the https://github.com/AnrDaemon/test-001/ , create a new branch from master and reproduce your issue.
Link the results here.
Back to top
View user's profile Send private message
yr4ik
Smarty Rookie


Joined: 06 Oct 2014
Posts: 14

PostPosted: Thu Apr 15, 2021 11:35 pm    Post subject: Reply with quote

https://github.com/yr4ik/smarty-bug-28005/tree/forum-28005
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1728

PostPosted: Tue Apr 20, 2021 4:12 pm    Post subject: Reply with quote

I'll test it once I have some free time.
Back to top
View user's profile Send private message
yr4ik
Smarty Rookie


Joined: 06 Oct 2014
Posts: 14

PostPosted: Tue Apr 20, 2021 8:48 pm    Post subject: Reply with quote

see compiled file. There will be an error in callback
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Bugs 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