"Subfetch" method idea

From: Date: Fri, 14 Jun 2002 10:25:16 +0000
Subject: "Subfetch" method idea
Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-142@lists.php.net to get a copy of this message
Hi, I just thought about a feature that might be interesting in Smarty. Since it provides very very advanced substitution functions, it would be nice if it could be used by scripts to run substitutions on string. It is basically what fetch does. By instance, i often use fetch to generate text email messages. In a script, i've got little class that loads an URL from a string, with parameters in it, and returns the URL with the parameters replaced by what you specified. So, just basic variables substitution. I thought at a moment about doing it with Smarty, but since i was using several URLs, i didn't want to create 5 or 10 templates. What i think is that we could add a tag in the templates that determines variables to retrieve using fetch (or a similar method). By instance, in variables.tpl: {fetchvar name='newslink'} http://www.somesite.com/news.php?news={$NEWS} {/fetchvar} {fetchvar name='userlink'} http://www.somesite.com/users.php?user={$USER} {/fetchvar} {fetchvar name='articlelink'} http://www.somesite.com/article.php?article={$ARTICLE}&mode={$MODE} {/fetchvar} And in links.php: ... // Two news $tpl->assign('NEWS', 5); $link1 = $tpl->fetch_var('variables.tpl', 'newslink'); $tpl->assign('NEWS', 7); $link2 = $tpl->fetch_var('variables.tpl', 'newslink'); // user link $tpl->assign('USER', katana); $userlink = $tpl->fetch_var('variables.tpl', 'userlink'); // article $tpl->assign('ARTICLE', '5'); $tpl->assign('MODE', 'comments'); $articlelink = $tpl->fetch_var('variables.tpl', 'articlelink'); Here is my idea... Any thougts ? Bertrand

« previous php.smarty.dev (#142) next »