You are here: Re: [SMARTY] Using modifiers with custom functions « Smarty Templates Posts « IT news, forums, messages
Re: [SMARTY] Using modifiers with custom functions

Posted by boots on 07/24/05 22:31

You didn't say what you expected to be returned, but I suspect that you
want to apply the modifier to the results of the funciton and not the
literal parameter. In other words:

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

BTW: on your last post you asked about assigning a function to Smarty.
I assume you got that resolved and no longer are trying to do things
like that. Even if it worked, you would probably need to resort to
PHP's poorly impemented create_function() ... which would still be a
non-started as $foo() notation in templates is not supported. The
proper way to get custom functions/functionality in Smarty is through
the plugin system.


--- Samuel Abels <newsgroups@debain.org> wrote:
> 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




____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация