Forum Moderators: coopster
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}>' ?> 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
$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.