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

skip the assign of variables
Goto page 1, 2  Next
 
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 -> General
View previous topic :: View next topic  
Author Message
Tony512
Smarty Rookie


Joined: 24 Jun 2006
Posts: 11

PostPosted: Sat Jun 24, 2006 8:25 am    Post subject: skip the assign of variables Reply with quote

hi all!
first..i'm a noob with smarty...so..sorry for my ignorance Very Happy Very Happy Very Happy
(and for my english too Razz )

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


Joined: 16 Jun 2006
Posts: 53

PostPosted: Sat Jun 24, 2006 9:01 am    Post subject: Reply with quote

please try to explain more detailed, or explain in german (if you are a german)!
Back to top
View user's profile Send private message
Tony512
Smarty Rookie


Joined: 24 Jun 2006
Posts: 11

PostPosted: Sat Jun 24, 2006 10:18 am    Post subject: Reply with quote

ok (sorry i'm italian Very Happy )..
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
View user's profile Send private message Visit poster's website
iriePub
Smarty Regular


Joined: 16 Jun 2006
Posts: 53

PostPosted: Sat Jun 24, 2006 12:57 pm    Post subject: Reply with quote

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


Joined: 24 Jun 2006
Posts: 11

PostPosted: Sat Jun 24, 2006 1:26 pm    Post subject: Reply with quote

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 Very Happy
Back to top
View user's profile Send private message Visit poster's website
iriePub
Smarty Regular


Joined: 16 Jun 2006
Posts: 53

PostPosted: Sat Jun 24, 2006 2:06 pm    Post subject: Reply with quote

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


Joined: 24 Jun 2006
Posts: 11

PostPosted: Sat Jun 24, 2006 2:26 pm    Post subject: Reply with quote

because i haven't understood it completely Very Happy
and i what to know if it's possible to skip the assign step Cool

about your code..
foreach($GLOBALS as $k => $v) {
what is $k and $v ? Question
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 Smile


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


Joined: 16 Jun 2006
Posts: 53

PostPosted: Sat Jun 24, 2006 3:23 pm    Post subject: Reply with quote

Tony512 wrote:
because i haven't understood it completely Very Happy
and i what to know if it's possible to skip the assign step Cool

about your code..
foreach($GLOBALS as $k => $v) {
what is $k and $v ? Question
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
View user's profile Send private message
Tony512
Smarty Rookie


Joined: 24 Jun 2006
Posts: 11

PostPosted: Sat Jun 24, 2006 4:49 pm    Post subject: Reply with quote

and...what rapresent $k,$v?

Quote:
and again, i don't understand it anymore^^
Very Happy
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..." Wink

thx
Back to top
View user's profile Send private message Visit poster's website
shannera
Administrator


Joined: 13 Feb 2006
Posts: 802
Location: Edertal, Germany

PostPosted: Sat Jun 24, 2006 6:33 pm    Post subject: Reply with quote

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
View user's profile Send private message
shannera
Administrator


Joined: 13 Feb 2006
Posts: 802
Location: Edertal, Germany

PostPosted: Sat Jun 24, 2006 6:39 pm    Post subject: Reply with quote

Tony512 wrote:
and...what rapresent $k,$v?


Before doing some intermediate PHP technic like Smarty, how about perfectioning the basics of PHP, like learning all the possible control structures? As shown in http://de3.php.net/manual/it/control-structures.foreach.php (italian language) or http://de3.php.net/manual/en/control-structures.foreach.php (english language) in the example block:
Code:

foreach(array_expression as $key => $value) istruzione

So it is most likely that iriePub uses $k for $key and $v for $value.
Back to top
View user's profile Send private message
iriePub
Smarty Regular


Joined: 16 Jun 2006
Posts: 53

PostPosted: Sat Jun 24, 2006 6:48 pm    Post subject: Reply with quote

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


Joined: 24 Jun 2006
Posts: 11

PostPosted: Sat Jun 24, 2006 7:20 pm    Post subject: Reply with quote

shannera wrote:


Before doing some intermediate PHP technic like Smarty, how about perfectioning the basics of PHP, like learning all the possible control structures? As shown in http://de3.php.net/manual/it/control-structures.foreach.php (italian language) or http://de3.php.net/manual/en/control-structures.foreach.php (english language) in the example block:
Code:

foreach(array_expression as $key => $value) istruzione

So it is most likely that iriePub uses $k for $key and $v for $value.


Twisted Evil i had understood the foreach function..i hadn't understood that $k --> $key and $v-->$value Very Happy Very Happy Very Happy



and...about the idea that i have written before?
(using {php}{/php} tags)
Back to top
View user's profile Send private message Visit poster's website
iriePub
Smarty Regular


Joined: 16 Jun 2006
Posts: 53

PostPosted: Sat Jun 24, 2006 10:42 pm    Post subject: Reply with quote

why don't you use my version, it works perfectly alright ...
Back to top
View user's profile Send private message
Tony512
Smarty Rookie


Joined: 24 Jun 2006
Posts: 11

PostPosted: Sat Jun 24, 2006 11:51 pm    Post subject: Reply with quote

yes..now i'm using your script..

i want to discover how much power is smarty Very Happy
Back to top
View user's profile Send private message Visit poster's website
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 -> General All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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