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

Retrieving template vars in PHP

 
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 -> Feature Requests
View previous topic :: View next topic  
Author Message
appel
Smarty Rookie


Joined: 27 May 2003
Posts: 29

PostPosted: Wed May 28, 2003 10:33 am    Post subject: Retrieving template vars in PHP Reply with quote

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
View user's profile Send private message
AZTEK
Smarty Pro


Joined: 16 Apr 2003
Posts: 235
Location: Purdue University

PostPosted: Wed May 28, 2003 11:00 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
appel
Smarty Rookie


Joined: 27 May 2003
Posts: 29

PostPosted: Wed May 28, 2003 11:08 am    Post subject: Reply with quote

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
View user's profile Send private message
AZTEK
Smarty Pro


Joined: 16 Apr 2003
Posts: 235
Location: Purdue University

PostPosted: Wed May 28, 2003 11:21 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
appel
Smarty Rookie


Joined: 27 May 2003
Posts: 29

PostPosted: Wed May 28, 2003 12:10 pm    Post subject: Reply with quote

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, .... Smile
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 -> Feature Requests 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