[SMARTY] Using modifiers with custom functions

Samuel Abels <[email protected]>
Newsgroups gmane.comp.php.smarty.general
Message-ID <1122208181.19303.12.camel@chef>
Hello,

I am trying to use a modifier with a custom function:

test.php:
-------------------
<?php
  require_once 'smarty/Smarty.class.php';
  
  function smarty_myfunc($params) {
    return "Test return value, [VAR].";
  }
  
  $smarty = &new Smarty();
  $smarty->template_dir = ".";
  $smarty->compile_dir  = "smarty/templates_c";
  $smarty->cache_dir    = "smarty/cache";
  $smarty->config_dir   = "smarty/configs";
  $smarty->register_function('func', 'smarty_myfunc');
  $smarty->assign('teststring', "Test string value, [VAR].");
  $smarty->display("test.tmpl");
?>
-------------------

test.tmpl:
-------------------
{$teststring|replace:"value":"REPLACEMENT"}

{func text="testarg"}<br>
{func text="testarg"|replace:"[VAR]":"REPLACEMENT"}<br>
{func text="testarg"|replace:"VAR":"REPLACEMENT"}<br>
{func text="testarg"|replace:"e":""}<br>
-------------------

This produces the following output:
-------------------
Test string REPLACEMENT, [VAR].
Test return value, [VAR].
Test return value, [VAR].
Test return value, [VAR].
Test return value, [VAR].
-------------------

In a more complex example, which I haven't been able to reproduce in a
simple test case, the last line in the template (|replace:"e":"")
produces the output "tstarg".

Am I doing something wrong? Sorry if I missed something obvious.

Thanks,
-Samuel

-- 
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.