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

compiler tags that simulate block tags.

 
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 -> Bugs
View previous topic :: View next topic  
Author Message
calguy1000
Smarty Rookie


Joined: 27 Mar 2009
Posts: 25

PostPosted: Sat Jun 09, 2012 2:23 am    Post subject: compiler tags that simulate block tags. Reply with quote

In smarty2 I have some compiler tags that are implemented as something that looks like a block tag. i.e: {my_tag}{* some smarty code *}{/my_tag}

What they do is generate a PHP 'if' statement based on some conditions. I need to replicate this in smarty3 without breaking existing code.

I just downloaded smarty 3.1.9 and created a simple inline test to try to reproduce this problem.

Code:
<?php
require_once(dirname(__FILE__).'/libs/Smarty.class.php');

function mytest_open($params,$smarty) {
  return "//mytest_open\n";
}
function mytest_close($params,$smarty) {
  return "//mytest_open\n";
}

$smarty = new Smarty;
$smarty->registerPlugin('compiler','mytest','mytest_open');
$smarty->registerPlugin('compiler','mytestclose','mytest_close'); // test1
//$smarty->registerPlugin('compiler','/mytest','mytest_close'); // test2
$smarty->display('string:{mytest}{* output some stuff from tags etc *}{/mytest}');
?>


This generates the following error:
Code:
Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "83906471dd5626c99b61d3f3714344222eaad2a2" on line 1 "{mytest}THIS IS A TESTX{/mytest}" unknown tag "mytestclose"' in /var/www/smarty_test1/libs/sysplugins/smarty_internal_templatecompilerbase.php:632 Stack trace: #0 /var/www/smarty_test1/libs/sysplugins/smarty_internal_templatecompilerbase.php(411): Smarty_Internal_TemplateCompilerBase->trigger_template_error('unknown tag "my...', 1) #1 /var/www/smarty_test1/libs/sysplugins/smarty_internal_templateparser.php(2498): Smarty_Internal_TemplateCompilerBase->compileTag('mytestclose', Array) #2 /var/www/smarty_test1/libs/sysplugins/smarty_internal_templateparser.php(3096): Smarty_Internal_Templateparser->yy_r58() #3 /var/www/smarty_test1/libs/sysplugins/smarty_internal_templateparser.php(3196): Smarty_Internal_Templateparser->yy_reduce(58) #4 /var/www/smarty_test1/libs/sysplugins/smarty_internal_smartytemplatecompiler.php(113): Smarty_Internal_Templateparser->doParse(0, 0) #5 /var/ in /var/www/smarty_test1/libs/sysplugins/smarty_internal_templatecompilerbase.php on line 632


Note, that commenting out the test1 line, and uncommenting the test2 line results in exactly the same error.

Can anybody help?


Last edited by calguy1000 on Sat Jun 09, 2012 3:58 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
calguy1000
Smarty Rookie


Joined: 27 Mar 2009
Posts: 25

PostPosted: Sat Jun 09, 2012 3:22 am    Post subject: Reply with quote

This code works great in smarty2.

Code:
<?php
require_once(dirname(__FILE__).'/libs/Smarty.class.php');

function mytest_open($params,$smarty) {
  echo "//mytest_open\n";
}
function mytest_close($params,$smarty) {
  echo "//mytest_close\n";
}

$smarty = new Smarty;
$smarty->template_dir = dirname(__FILE__).'/templates';
$smarty->compile_dir = dirname(__FILE__).'/templates_c';
$smarty->register_compiler_function('mytest','mytest_open');
$smarty->register_compiler_function('/mytest','mytest_close');

$smarty->display('test.tpl');
?>
Back to top
View user's profile Send private message Visit poster's website
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sat Jun 09, 2012 2:02 pm    Post subject: Reply with quote

This bug is fixed now in the SVN trunk and will later be included in 3.1.10

You must use
$smarty->registerPlugin('compiler','mytestclose','mytest_close');
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 -> 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