|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
appel Smarty Rookie
Joined: 27 May 2003 Posts: 29
|
Posted: Wed May 28, 2003 10:33 am Post subject: Retrieving template vars in PHP |
|
|
Yes, I want a method that gets all the variables in a template document.
E.g.
index.tpl:
<html>
<body>
{$var_1} and {$var_2}
</body>
</html>
index.php:
include("Smarty.class.php");
$smarty = new Smarty();
$arrvars = $smarty->getAllTplVars('index.tpl');
$arrVars should now contain:
$arrVars[0] = 'var_1';
$arrVars[1] = 'var_2'; |
|
Back to top |
|
AZTEK Smarty Pro
Joined: 16 Apr 2003 Posts: 235 Location: Purdue University
|
Posted: Wed May 28, 2003 11:00 am Post subject: |
|
|
http://smarty.php.net/manual/en/api.get.template.vars.php _________________ "Imagine a school with children that can read and write, but with teachers who cannot, and you have a metaphor of the Information Age in which we live." -Peter Cochrane |
|
Back to top |
|
appel Smarty Rookie
Joined: 27 May 2003 Posts: 29
|
Posted: Wed May 28, 2003 11:08 am Post subject: |
|
|
AZTEK wrote: | http://smarty.php.net/manual/en/api.get.template.vars.php |
That's not what I mean. This method only allows you to retrieve variables you have already assigned, e.g.:
index.tpl:
Code: | <html>
<body>
{$var_1} and {$var_2}
</body>
</html> |
index.php:
Code: | include("Smarty.class.php");
$smarty = new Smarty();
$smarty->assign('var_1','blabla');
$arrVars = $smarty->get_template_vars(); |
$arrVars now contains: (doesn't contain var_2)
$arrVars['var_1'] = 'blabla';
This should be:
index.php:
Code: | include("Smarty.class.php");
$smarty = new Smarty();
$arrVars = $smarty->get_template_vars('index.tpl'); |
$arrVars now contains:
$arrVars[0] = 'var_1';
$arrVars[1] = 'var_2'; |
|
Back to top |
|
AZTEK Smarty Pro
Joined: 16 Apr 2003 Posts: 235 Location: Purdue University
|
Posted: Wed May 28, 2003 11:21 am Post subject: |
|
|
Well there isn't really a way to do that that I know of. Since the $smarty->_tpl_vars array only holds defined values probably the only way would be to have someone write up a regex but then you still wouldn't get vars not used between deliminators. _________________ "Imagine a school with children that can read and write, but with teachers who cannot, and you have a metaphor of the Information Age in which we live." -Peter Cochrane |
|
Back to top |
|
appel Smarty Rookie
Joined: 27 May 2003 Posts: 29
|
Posted: Wed May 28, 2003 12:10 pm Post subject: |
|
|
AZTEK wrote: | Well there isn't really a way to do that that I know of. Since the $smarty->_tpl_vars array only holds defined values probably the only way would be to have someone write up a regex but then you still wouldn't get vars not used between deliminators. |
Yes, that's why this is a feature request. I can work with:
Code: | preg_match_all('/{\$(.*?)}/',implode('',file('templates/index.tpl')),$arrReturned,2); |
And $arrReturned contains:
Code: | Array
(
[0] => Array
(
[0] => {$var_1}
[1] => var_1
)
[1] => Array
(
[0] => {$var_2}
[1] => var_2
)
) |
But, .... |
|
Back to top |
|
|
|
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
|