On 3 Sep 2004 16:34:08 -0700,
wi*****@usa.net (Richard) wrote:
I need help. I have a smarty based program that I am modifying. I
have a smarty template file that consists of smarty and HTML.
I need to integrate some PHP database calls into it. My problem is I
cannot figure out how to pass value between smarty and PHP. Going
from php to smarty I've tried this:
{php}
$smarty = new Smarty;
$smarty->assign("x", 100);
{/php}
<br>{$x}<br>
So the value $x comes out blank. Shouldn't it be "100"?
and in smarty after this point how do I reference the $x variable?
Why are you using {php} in templates and not in the .php script?
<?php
$smarty = new Smarty;
[ setup smarty required dirs here ]
$smarty->assign('x', 100);
$smarty->display('page.tpl');
?>
{* Smarty template *}
<div>Value assigned to x is: {$x}</div>
----------------------
Next question. How do I give php values from smarty. For example if
there is a loop like:
{section name=xyz loop=$zzz}
{php}
How do i get to $xyz from in here (php)?
{/php}
{/section}
---------------------
I just know someone out there knows the answer - HELP!
<?php
$smarty = new Smarty;
[ setup smarty required dirs here ]
$xyzArray = array('foo', 'bar', 'baz');
$smarty->assign('xyz', $xyzArray);
$smarty->display('page.tpl');
?>
{* Smarty template *}
<ul>
{section name=i loop=$xyz}
<li>{$xyz.i}</li>
{sectionelse}
<li>No values to display</li>
{/section}
</ul>
OR
{* Smarty template *}
<ul>
{foreach from=$xyz item=foo}
<li>{$foo}</li>
{foreachelse}
<li>No values to display</li>
{/foreach}
Using {php} tags in the template kind of defeats the object of using the
templates in the first place and can lead to problems if not careful.
HTH =)
Regards,
Ian
--
Ian.H
digiServ Network
London, UK
http://digiserv.net/