Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie Help Please

Status
Not open for further replies.

MrTBC

Technical User
Nov 19, 2003
610
US
Hi guys,
I'm after some really basic help please.

I have a file "sponsors.php" which contains:

<?PHP
$fcontents = join ('', file ('content.txt'));
$s_con = split("~",$fcontents);
$banner_no = (rand()%(count($s_con)-1));
echo $s_con[$banner_no];
?>

And a second file sponsors.tpl:

(empty)

What do I need to put in sponsors.tpl so it displays the value currently displying in sponsors.php please?

Thanks very much.
 
A .tpl file might be a PHP Development Template [a number of Open Source PHP development projects (e.g., phpBB and others) use templates for formatting].

I would guess that file is left over from something else.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Hi there,
Thanks, but I do need to pass the value from the php file to a tpl file.
 
You'd probably have to set a session variable or something from the php file and then read that session variable inside the .tpl file (assuming that these files are parsed server-side by PHP).

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Thanks Jeff. Unfortunately I know a big fat ZERO about PHP.
 
Try this then... insert a couple of new lines after the echo in sponsors.php:
Code:
echo $s_con[$banner_no];
if(!session_id()) session_start();
$_SESSION['banner_data'] = $s_con[$banner_no];
Then insert this into the file sponsors.tpl and see if it works:
Code:
<?php echo $_SESSION['banner_data']; ?>
Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Thanks Jeff. The problem I've having is with putting any PHP in the tpl file, so I was hoping to pass the value across as a variable.
 
It sounds to me that you want to write the actual PHP code to the .tpl file.

I would follow Jeff advise but making the code part of the string you are passing.

Hope you do not mind my asking but, why this approach? It is sometimes better to explain your reasons beside your objectives and probably, an experienced (not me) member would provide a suitable solution.

Regards,


Jose Lerebours


KNOWLEDGE: Something you can give away endlessly and gain more of it in the process! - Jose Lerebours
 
OK thank you. Let me step back a bit here.

I am trying to make a change to an existing script (PHPLD) so that I can display some affiliate ads.

Existing script file:

Sidebar.tpl:

Code:
{strip} 
<table width="171" border="0" cellpadding="0" cellspacing="0" class="bars">
  <tr> 
    <td class="barsl"></td>
    <td>Partners</td>
    <td class="barsr"></td>
  </tr>
</table>
<table width="171" border="0" cellpadding="0" cellspacing="0" class="partners">
  <tr>
	<td valign="top" class="cpad">{include file="sponsors.tpl"}</td>
  </tr>
</table><br />
{/strip}

You can see that sidebar.tpl has this statement in:

Code:
{include file="sponsors.tpl"}

The idea is that you just put some links in sponsors.tpl - but that's no good for me.

What I'm instead trying to incorporate instead of sponsors.tpl is the result of this PHP code:

Code:
<?PHP
$fcontents = join ('', file ('content.txt'));
$s_con = split("~",$fcontents);  
$banner_no = (rand()%(count($s_con)-1)); 
echo $s_con[$banner_no]; 
?>

Any ideas please? Thanks very much guys.
 
What your script is using is called Smarty. Find the variable that the class object of Smarty was stored:

Something like:
Code:
$myvar = new Smarty ( );

And use that variable to assign a value:

Code:
$myvar->assign( "mycontent", $s_con[$banner_no] )

And then in the template:
Code:
{$mycontent}

can be used where ever you need the content.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top