473,395 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

PHP/Smarty - Going crazy (slowly)

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?

----------------------

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!
Jul 17 '05 #1
1 2283
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/
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Brian | last post by:
Hello, I am trying to work out how to have smarty use a string's contents as the display-> template.. ie: $smarty->display($buffer); obviously $buffer isn't a filename, but a smarty template...
2
by: Daan | last post by:
Hello all, I'm having a little problem with Smarty. Getting it to work in a simple case went fine, but now I have the following situation: / /smarty /templates template.tpl /templates_c
2
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
2
by: M | last post by:
Hi Folks, I am trying to install Smarty using PHP 5 on a Windows XP PC using IIS v6 The following PHP File: <!doctype html public "-//W3C//DTD HTML 4.0 //EN"> <html> <head>
0
by: Matt | last post by:
geez, i've done this a million times, you'd think i could get it right. uploading to production server for a new site, and part of the head.inc that starts everything up looks like this: echo...
0
by: Conrad | last post by:
Hi, I'm very new to Smarty Template Engine and I'm using PHP 5.0.4 on the Windows XP Professional platform and I have the following question: When I change the 7th line of the script to use a...
0
by: ev45ive | last post by:
Hi! I have smth. like this: file.php: <?php SmartyValidate::connect($smarty); //SmartyValidate::register_form('register');
0
by: grezlik | last post by:
Hi! I have major problems with cakephp & smarty, (cake ver is 1.2 and smarty 2.6.18 ) there is a code (from cake/libs/view/view.php class SmartyView { .. .. ..
1
by: ajaymohank | last post by:
hello friends.......... i am new to smarty. can anyone please tell me how to get the value from a dynamically generated checkbox using smarty. this is the code i used... here i am generating 10...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.