Hi
I still learning how Smarty templates works. I can't seem to make the image appear on the Smarty Template.
I try to used this {html_image}
it doesn't work.
I used <img>
instead.
<img src="images/{$book->image[tbl]}" width="115">
These are my files.
This is my index.php
<?php
require("libs/Smarty.class.php");
require_once("get_data.php");
require_once("books.php");
$book = new n_books();
$smarty = new Smarty();
$smarty->assign("book",$book);
$output = $smarty->fetch('index.tpl');
$smarty->display('index.tpl');
?>
This is my index.tpl
<html>
<head>
<title> Book Sale </title>
</head>
<body>
<table border="0" width="100%">
<tr>
<td>
<h1> Book Sale</h1>
</td>
</tr>
</table>
<table border="1" width="50%">
{section name=tbl loop=$book->title}
<tr>
<td align="left">
<table>
<tr>
<td>
<img src="images/{$book->image[tbl]}" width="115">
</td>
<td valign="top">
<font size=+1><b> {$book->title[tbl]} </b></font><br>
<font size=-1 color=blue><b> {$book->author[tbl]} </b></font><br>
{$book->description[tbl]} <br>
</td>
</tr>
</table>
</td>
{/section}
</tr>
</table>
</body>
</html>
This is my get_data.php
<?php
class books {
//public
public $title = array();
public $image = array();
public $author = array();
public $description = array();
// private
private $filename = "bookdata.txt";
//class constructor
function __construct(){
//get the lines as an array
$i=-1;
$lines = file($this->filename);
// get each variable in an array
foreach ( $lines as $line) {
if (strlen($line) > 2) {
$line = rtrim($line);
list($what, $content) = explode("=>", $line);
if ($what == "Title") {
$i++;
$this->title[$i]=$content;
}
elseif ($what == "Image") {
$this->image[$i]=$content;
}
elseif ($what == "Author") {
$this->author[$i]=$content;
}
elseif ($what == "Description") {
$this->description[$i]=$content;
}
};
};
} // end constructor
} // end GetData
?>
This is my books.php
<?php
class n_books {
//public
public $title = array();
public $image = array();
public $author = array();
public $description = array();
//private
protected $DataObject;
function __construct(){
$this->DataObject = new books();
$this->title = $this->DataObject->title;
$this->image = $this->DataObject->image;
$this->author = $this->DataObject->author;
$this->description = $this->DataObject->description;
}
} // end class n_books
?>
This is my bookdata.txt
Title=> Book 1
Image=> 1.jpg
Author=> Sam Rock
Description=> Book 1 demo
Title=> Book 2
Image=> 2.jpg
Author=> John Rock
Description=> Book 2 demo
Title=> Book 3
Image=> 3.jpg
Author=> Tim Rock
Description=> Book 3 demo
Title=> Book 4
Image=> 4.jpg
Author=> Chris Rock
Description=> Book 4 demo
I attached an image of the template how it looks like now but it doesn't have image appear yet.
Any Suggestions and explanation will help. I appreciate it. Thanks!