Jump to content

Can't Get $value to Show in TPL


rtrdogs

Recommended Posts

I have 3 files I'm working with from a news management script. I'm trying to get a PHP file that shows three news headlines to appear on a TPL file. Includes aren't working in TPL files within this news management system, although I have PHP includes in my own TPL files that are parsing just fine throughout my site.

 

So what I've got here is index.php, header.php and then an index.tpl file. I've created booknews.php that shows the newest three headlines.

 

First, a snippet from the index.php file that I've added the $booknews value to but not sure if it's doing anything.

 

I've added stars like: ***** around the code so you can see what I've changed.

 

function main($offset, $limit)
{
global $logo, $adminarea, $skin, $home, $recent, ***** $booknews, ***** $bookauthor, $catslink, $authors, $help, $search, $login, $titles, $logout, $itemsperpage, $columns;
include ("header.php");

$result = mysql_query("SELECT welcome, copyright from news_settings");
$settings = mysql_fetch_array($result);

//make a new TemplatePower object
$tpl = new TemplatePower( "skins/$skin/index.tpl" );
$tpl->assignInclude( "newsbox", "./skins/$skin/newsbox.tpl" );

//let TemplatePower do its thing, parsing etc.
$tpl->prepare();

//assign a value to {name}
$tpl->assign( "welcome", $settings[welcome] );
$tpl->assign( "footer", $settings[copyright] );
$tpl->assign( "logo", $logo );
$tpl->assign( "home", $home );
$tpl->assign( "recent", $recent );
***** $tpl->assign( "booknews", $booknews ); *****
$tpl->assign( "bookauthor", $bookauthor );
$tpl->assign( "catslink", $catslink );
$tpl->assign( "authors", $authors );
$tpl->assign( "help", $help );
$tpl->assign( "search", $search );
$tpl->assign( "login", $login );
$tpl->assign( "adminarea", $adminarea );
$tpl->assign( "titles", $titles );
$tpl->assign( "logout", $logout );

if (empty($offset) || $offset < 0)
	{
		$offset=0;
	}
	if (empty($index)) $index=0;
	$limit = $itemsperpage;

$result2 = mysql_query("SELECT *,DATE_FORMAT(time, '%m/%d/%Y - %h:%i%p') as date FROM news_news ORDER BY nid DESC LIMIT $offset,$limit");
$count =  mysql_query("SELECT count(*) FROM news_news ORDER BY nid DESC");
list($numrows)= mysql_fetch_array($count);
$index++;
while($stories = mysql_fetch_array($result2))
	{

	//create a new number_row block
	$tpl->newBlock("newsbox");

	//assign values
	$tpl->assign("newstitle"   , $stories[title] );
	$tpl->assign("newsstory"   , $stories[story] );
	$tpl->assign("newsauthor", $stories[author] );
	$tpl->assign("newsdate", $stories[date] );
	}

(I truncated the code here for length purposes but if you need to see the rest, just let me know.)

 

 

 

 

Snippet from header.php

 

include ($databasepath."/dbconfig.php");
include ("lib/class.TemplatePower.inc.php");
include ("languser.php");


$home = "<a class=\"menu\" href=\"index.php\">"._HOME."</a>";
$catslink = "<a class=\"menu\" href=\"categories.php\">"._CATEGORIES."</a>";
$bookauthor = "<a class=\"menu\" href=\"byauthor.php\">"._BOOKAUTHOR."</a>";
***** $booknews = "<a class=\"menu\" href=\"booknews.php\">"._BOOKNEWS."</a>"; *****
$recent = "<a class=\"menu\" href=\"search.php?action=recent\">"._RECENTLYADDED."</a>";
$authors = "<a class=\"menu\" href=\"authors.php?action=list\">"._AUTHORS."</a>";
$help = "<a class=\"menu\" href=\"help.php\">"._HELP."</a>";
$search = "<a class=\"menu\" href=\"search.php\">"._SEARCH."</a>";
$titles = "<a class=\"menu\" href=\"titles.php\">"._TITLES."</a>";

 

The code above, displays the _BOOKNEWS link just fine. I've tried a few variations to show the booknews.php include file. Like:

 

$booknews = require_once("booknews.php");

 

or

 

$booknews = include ("booknews.php");

 

Nothing shows up in the area where the link shows up just fine.

 

 

How index.tpl calls for booknews:

 

{booknews}

 

Not really sure where to go from here. I've searched for hours, tried variations and I'm just completely stumped.

Link to comment
https://forums.phpfreaks.com/topic/89485-cant-get-value-to-show-in-tpl/
Share on other sites

well if you go by this way it will not show you it will return 1 or other value as it is not the correct way of including some file.

 

In second code book code link work becuase on click you process a file called booknews.php .

 

while templating you are using???

 

if($var == 'book')

  $file_to_be_include='booknews.php'

elseif()

  $file_to_be_include='booknews.php'

.

.

.

.

.

 

and in your template use {include file="$file_to_be_included"} to include the files content. (this is in smarty) use the same way in your template engine.

 

Regards

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.