View previous topic :: View next topic |
Author |
Message |
Tony512 Smarty Rookie
Joined: 24 Jun 2006 Posts: 11
|
Posted: Sat Jun 24, 2006 8:25 am Post subject: skip the assign of variables |
|
|
hi all!
first..i'm a noob with smarty...so..sorry for my ignorance
(and for my english too )
is possible to skip the assing of the variables?
when i do the display of the template smarty takes by himself the variabiles form the php files.
bye ..W smarty! |
|
Back to top |
|
iriePub Smarty Regular
Joined: 16 Jun 2006 Posts: 53
|
Posted: Sat Jun 24, 2006 9:01 am Post subject: |
|
|
please try to explain more detailed, or explain in german (if you are a german)! |
|
Back to top |
|
Tony512 Smarty Rookie
Joined: 24 Jun 2006 Posts: 11
|
Posted: Sat Jun 24, 2006 10:18 am Post subject: |
|
|
ok (sorry i'm italian )..
so..i have a php file where i set some variables and load the template:
[php:1:358e1aaea9]
//set variables
$a=10;
$b=$a-3;
$c=($b+$a)*2;
//load template
require('./includes/setup_smarty.php');
$smarty = new Smarty;
//assign templates variables
/*this is the part that i want to skip*/
$smarty->assign('a',$a);
$smarty->assign('b',$b);
$smarty->assign('c',$c);
/* smarty can catch by himself the variables? */
//print the template
$smarty->display('exemple.tpl');
[/php:1:358e1aaea9]
and a simple tpl file:
[php:1:358e1aaea9]
1. {a}
2. {b}
3. {c}
[/php:1:358e1aaea9]
i don't want each time to do the assign of all variables...
i want to know if there is a method for smarty to catch the variables by himself when there is "$smarty->display('exemple.tpl');" |
|
Back to top |
|
iriePub Smarty Regular
Joined: 16 Jun 2006 Posts: 53
|
Posted: Sat Jun 24, 2006 12:57 pm Post subject: |
|
|
ah i understand. you have to do it in php. perhaps this works for you:
[php:1:3c2cbc2b99]
$a = 10;
$b = $a-3;
$c = ($b+$a)*2;
foreach($GLOBALS as $k => $v) {
$smarty->assign($k, $v);
}
[/php:1:3c2cbc2b99]
untested! |
|
Back to top |
|
Tony512 Smarty Rookie
Joined: 24 Jun 2006 Posts: 11
|
Posted: Sat Jun 24, 2006 1:26 pm Post subject: |
|
|
yes...i have thought at something in php to assign all variables ..
but, that i want to know is if there is someway to pass the variables at smarty without writing anything...
like when i do the eval of a string...
thx |
|
Back to top |
|
iriePub Smarty Regular
Joined: 16 Jun 2006 Posts: 53
|
Posted: Sat Jun 24, 2006 2:06 pm Post subject: |
|
|
i don't know, but why don't you just my snippet of code. isn't it working or don't you like it? |
|
Back to top |
|
Tony512 Smarty Rookie
Joined: 24 Jun 2006 Posts: 11
|
Posted: Sat Jun 24, 2006 2:26 pm Post subject: |
|
|
because i haven't understood it completely
and i what to know if it's possible to skip the assign step
about your code..
foreach($GLOBALS as $k => $v) {
what is $k and $v ?
and $GLOBALS is an array with all the variables defined, right?
but i want to assign only some variables...not all variables
(only that are in the template file)
how i can do this?
thx
Idea:
if instead of using normal smarty tag to write variables (ex {$xxx}) i use the smarty php tag?
[php:1:055f00510e]
{php}
echo $xxx
{/php}
[/php:1:055f00510e]
the variable $xxx doesn't need to be assigned to smarty..but does it take the same value that it has in php files? |
|
Back to top |
|
iriePub Smarty Regular
Joined: 16 Jun 2006 Posts: 53
|
Posted: Sat Jun 24, 2006 3:23 pm Post subject: |
|
|
Tony512 wrote: | because i haven't understood it completely
and i what to know if it's possible to skip the assign step
about your code..
foreach($GLOBALS as $k => $v) {
what is $k and $v ?
and $GLOBALS is an array with all the variables defined, right?
|
yes, right
Tony512 wrote: |
but i want to assign only some variables...not all variables
(only that are in the template file)
how i can do this? |
and again, i don't understand it anymore^^ |
|
Back to top |
|
Tony512 Smarty Rookie
Joined: 24 Jun 2006 Posts: 11
|
Posted: Sat Jun 24, 2006 4:49 pm Post subject: |
|
|
and...what rapresent $k,$v?
Quote: | and again, i don't understand it anymore^^ |
for exemple:
[php:1:f13041cf45]
$age='age:';
$a=10;
$b=30;
$c=$a+$b;
[/php:1:f13041cf45]
and i want to pass to smarty only $age and $c if i do "foreach($GLOBALS..."
thx |
|
Back to top |
|
shannera Administrator
Joined: 13 Feb 2006 Posts: 802 Location: Edertal, Germany
|
Posted: Sat Jun 24, 2006 6:33 pm Post subject: |
|
|
iriePub wrote: |
Tony512 wrote: |
but i want to assign only some variables...not all variables
(only that are in the template file)
how i can do this? |
and again, i don't understand it anymore^^ |
He wants that automagically all variables are assigned with values that are in the template. Tonys error in reasoning is that smarty or whatever can't know which value has to be assigned to each variable in the template. |
|
Back to top |
|
shannera Administrator
Joined: 13 Feb 2006 Posts: 802 Location: Edertal, Germany
|
|
Back to top |
|
iriePub Smarty Regular
Joined: 16 Jun 2006 Posts: 53
|
Posted: Sat Jun 24, 2006 6:48 pm Post subject: |
|
|
shannera wrote: | iriePub wrote: |
Tony512 wrote: |
but i want to assign only some variables...not all variables
(only that are in the template file)
how i can do this? |
and again, i don't understand it anymore^^ |
He wants that automagically all variables are assigned with values that are in the template. Tonys error in reasoning is that smarty or whatever can't know which value has to be assigned to each variable in the template. |
yes, then, I did understand it the right way. tony confused me posting his wishes again after I had posted a code, that does, what he wanted ... |
|
Back to top |
|
Tony512 Smarty Rookie
Joined: 24 Jun 2006 Posts: 11
|
Posted: Sat Jun 24, 2006 7:20 pm Post subject: |
|
|
i had understood the foreach function..i hadn't understood that $k --> $key and $v-->$value
and...about the idea that i have written before?
(using {php}{/php} tags) |
|
Back to top |
|
iriePub Smarty Regular
Joined: 16 Jun 2006 Posts: 53
|
Posted: Sat Jun 24, 2006 10:42 pm Post subject: |
|
|
why don't you use my version, it works perfectly alright ... |
|
Back to top |
|
Tony512 Smarty Rookie
Joined: 24 Jun 2006 Posts: 11
|
Posted: Sat Jun 24, 2006 11:51 pm Post subject: |
|
|
yes..now i'm using your script..
i want to discover how much power is smarty |
|
Back to top |
|
|