Smarty Guru please~~ Remove template;

Here is a very tiny program(3 files) has embedded with Smarty template engine.
Anyone knows how to remove Smarty completely?
Complete source files as in attachment.

index.php
[php]

<?php require("comm/Smarty.class.php"); require_once("get_data.php"); require_once("books.php"); $book = new bo_books(); $book->apply_discount(); $smarty = new Smarty; $smarty->assign("book",$book); $smarty->display('index.tpl'); ?>

[/php]

get_data.php
[php]

<?php class books { //public public $title = array(); public $image = array(); public $author = array(); public $description = array(); public $year = array (); public $price = array(); // private private $filename = "data.txt"; //class constructor function __construct() { //get the lines as an array $i=-1; $lines = file($this->filename); // strip "\n" at the end of each array // 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; } elseif ($what == "Year") { $this->year[$i]=$content; } elseif ($what == "Price") { $this->price[$i]=$content; }; }; }; } // end constructor } // end GetData ?>

[/php]

books.php
[php]

<?php class bo_books { //public public $title = array(); public $image = array(); public $author = array(); public $description = array(); public $year = array (); public $price = array(); public $discount = array(); public $discounted = array(); //private protected $DataObject; function __construct() { $this->DataObject = new books(); } public function apply_discount() { $this->title = $this->DataObject->title; $this->image = $this->DataObject->image; $this->author = $this->DataObject->author; $this->description = $this->DataObject->description; $this->year = $this->DataObject->year; $this->price = $this->DataObject->price; $j = 0; foreach($this->year as $year) { if ($this->year[$j] == '2004') $this->discount[$j] = '20'; elseif ($this->year[$j] == '2005') $this->discount[$j] = '10'; $this->discounted[$j] = intval($this->price[$j] * (100 - $this->discount[$j]) ) / 100 ; $j++; }; } // end function apply_discount() } // end class bo_books ?>

[/php]

data.txt
[php]
Title=> Building Websites with VB.NET and DotNetNuke 3.0
Image=> 1904811272.jpg
Author=> Daniel N. Egan
Description=> A practical guide to creating and maintaining your own website with DotNetNuke, the free, open source evolution of Microsoft’s IBuySpy Portal
Year=> 2005
Price=> 39.99

Title=> SSL VPN : Understanding, evaluating and planning secure, web-based remote access
Image=> 1904811078.jpg
Author=> Joseph Steinberg, Tim Speed, Simon Jenner
Description=> A comprehensive overview of SSL VPN technologies and design strategies
Year=> 2005
Price=> 49.99

Title=> Windows Server 2003 Active Directory Design and Implementation=> Creating, Migrating, and Merging Networks
Image=> 1904811086.jpg
Author=> John Savill
Description=> A unique, scenario-based approach to selecting and implementing the best Active Directory design for your environment
Year=> 2005
Price=> 59.99

Title=> Building Websites with the ASP.NET Community Starter Kit
Image=> 1904811000.jpg
Author=> Cristian Darie, K. Scott Allen

Description=> A comprehensive guide to understanding, implementing, and extending the powerful and freely available application from Microsoft
Year=> 2004
Price=> 44.99

[/php]

I konw the procedure to remove Smarty but failed to rewrite the code to pure PHP.

If you post the index.tpl source I may be able to point you in the right direction.

Here’s two file.
i) First one ; index.tpl

ii) Second one ; compiled_index.tpl.php
~~ the compiled file from index.tpl in cache (templates_c) folder.

i) First one ; index.tpl
[php]

Site Architecture Example

Chapter 2 Example


Here are the books in a two-column table :

{section name=tbl loop=$book->title}

{if %tbl.index% is not odd}

{/if}

{if %tbl.index% is odd}

{/if}

{/section}

<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>
  Year: {$book->year[tbl]} <br>
  <font size=-1>Cover Price: <s>${$book->price[tbl]}</s></font> <br>
  Our Price: ${$book->discounted[tbl]} 
  <font color=red> save {$book->discount[tbl]} % </font>
</td>
[/php]

ii) Second one ; compiled_index.tpl.php
[php]

<?php /* Smarty version 2.6.27, created on 2012-10-29 13:04:16 compiled from index.tpl */ ?> Site Architecture Example

Chapter 2 Example


Here are the books in a two-column table :

<?php unset($this->_sections['tbl']); $this->_sections['tbl']['name'] = 'tbl'; $this->_sections['tbl']['loop'] = is_array($_loop=$this->_tpl_vars['book']->title) ? count($_loop) : max(0, (int)$_loop); unset($_loop); $this->_sections['tbl']['show'] = true; $this->_sections['tbl']['max'] = $this->_sections['tbl']['loop']; $this->_sections['tbl']['step'] = 1; $this->_sections['tbl']['start'] = $this->_sections['tbl']['step'] > 0 ? 0 : $this->_sections['tbl']['loop']-1; if ($this->_sections['tbl']['show']) { $this->_sections['tbl']['total'] = $this->_sections['tbl']['loop']; if ($this->_sections['tbl']['total'] == 0) $this->_sections['tbl']['show'] = false; } else $this->_sections['tbl']['total'] = 0; if ($this->_sections['tbl']['show']): for ($this->_sections['tbl']['index'] = $this->_sections['tbl']['start'], $this->_sections['tbl']['iteration'] = 1; $this->_sections['tbl']['iteration'] <= $this->_sections['tbl']['total']; $this->_sections['tbl']['index'] += $this->_sections['tbl']['step'], $this->_sections['tbl']['iteration']++): $this->_sections['tbl']['rownum'] = $this->_sections['tbl']['iteration']; $this->_sections['tbl']['index_prev'] = $this->_sections['tbl']['index'] - $this->_sections['tbl']['step']; $this->_sections['tbl']['index_next'] = $this->_sections['tbl']['index'] + $this->_sections['tbl']['step']; $this->_sections['tbl']['first'] = ($this->_sections['tbl']['iteration'] == 1); $this->_sections['tbl']['last'] = ($this->_sections['tbl']['iteration'] == $this->_sections['tbl']['total']); ?> <?php if (!((1 & $this->_sections['tbl']['index']))): ?>
	<tr>
<?php endif; ?>
	<td align="left">
	  <table>
	   <tr>
		<td>             <!-- image path -->
		  <img src="./images/<?php echo $this->_tpl_vars['book']->image[$this->_sections['tbl']['index']]; ?>

" width=“220”>

		<td valign="top"><!-- Title -->
		  <font size=+1><b> <?php echo $this->_tpl_vars['book']->title[$this->_sections['tbl']['index']]; ?>




<?php echo $this->_tpl_vars['book']->author[$this->_sections['tbl']['index']]; ?>



<?php echo $this->_tpl_vars['book']->description[$this->_sections['tbl']['index']]; ?>



Year: <?php echo $this->_tpl_vars['book']->year[$this->_sections['tbl']['index']]; ?>



Cover Price: $<?php echo $this->_tpl_vars['book']->price[$this->_sections['tbl']['index']]; ?>



Our Price: $<?php echo $this->_tpl_vars['book']->discounted[$this->_sections['tbl']['index']]; ?>

                         <!-- Discount -->
		  <font color=red> save <?php echo $this->_tpl_vars['book']->discount[$this->_sections['tbl']['index']]; ?>

%

		</td>
	   </tr>
	  </table>
	</td> 
<?php if ((1 & $this->_sections['tbl']['index'])): ?>
    </tr>
<?php endif; ?> <?php endfor; endif; ?>
[/php]

It is really very simple, all you have to do is change the {section name=tbl loop=$book->title} to a foreach loop and remove the smarty tags from within that loop.

wow~~ I’m deeply appreciated.
Thanks a lot.

Sponsor our Newsletter | Privacy Policy | Terms of Service