Forum Moderators: coopster

Message Too Old, No Replies

smarty variables

smarty tags, variables

         

frogz

3:29 am on Jan 11, 2009 (gmt 0)

10+ Year Member



I'm sure someones familiar with smarty variables, they look like <{$uid.post}>

a quick question plz, does anyone know how I can echo the smarty variable within php?

<?php echo <{$uid.post}> ?>
should work but it throws a blank page. when I use:
<?php echo '<{$uid.post}>' ?>

of course it just shows the text variable itself.

when I use the variable by itself outside of <?php ?> it works fine, but I need to use <{$uid.post}> inside of a php argument, only calling on it under certain conditions.

It seems I cannot initiate the variable within php as an echo or print.
was wondering if theres a way I can escape php to display the variables within the php argument?

hope this makes sense..

thank you

frogz

4:31 am on Jan 11, 2009 (gmt 0)

10+ Year Member



this coincides with my last post here, Within my "echo" I cannot include my variable now, I thought I was out of the woods :(

frogz

5:25 am on Jan 11, 2009 (gmt 0)

10+ Year Member



$Info_1 = <html><{$smart>}></html>;
$Info_2 = <html></html>;

if ($_SERVER['REQUEST_URI'], 'post') !== FALSE) {

echo $Info_1;
} else {
echo $Info_2;
}

..blank page

frogz

5:59 am on Jan 11, 2009 (gmt 0)

10+ Year Member



HAAAAAAAAAAAA YUEAAAAAAHHHHH! I did it!

I went around this problem and used a "switch" to just simply switch the complete template up upon certain requests!

couldnt have done it without the help of this place though, thanks!

dreamcatcher

12:06 pm on Jan 11, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad you got it sorted frogz.

dc

bkeep

2:02 pm on Jan 11, 2009 (gmt 0)

10+ Year Member



What you should be doing is instead of this

$Info_1 = <html><{$smart>}></html>;
$Info_2 = <html></html>;

if ($_SERVER['REQUEST_URI'], 'post') !== FALSE) {

echo $Info_1;
} else {
echo $Info_2;
}

use this


$smarty = new Smarty;

$Info_1 = <html><{$smart>}></html>;
$Info_2 = <html></html>;

if ($_SERVER['REQUEST_URI'], 'post') !== FALSE) {
$smarty->assign("info","$Info_1");
} else {
$smarty->assign("info","$Info_2");
}

then in your template use it like so


{if $info}
{$info}
{/if}

and if you have an associative array


$user = array(
'uid' => '12',
'name' => 'bob',
'age' => 29
);

in php
print $user["uid"]; //outputs 12

using smarty
$smarty->assign("user","$user");

then to display in your template you would use a foreach like so


{foreach item="records" from=$user}
{$records.uid} <!-- outputs 12 -->
{/foreach}

That is sort of the quick and dirty but you should get the idea.

frogz

8:05 am on Jan 18, 2009 (gmt 0)

10+ Year Member



Thanks Dreamcatcher!

bkeep.. dude.. you rock! although I have found a workaround, what you have done will most certainly be useful in the future.

for this, I thank you, ALL of you!

peace!
frogz