Page 1 of 1
which template engine used?
Posted: Wed Jul 22, 2009 2:50 pm
by noescape
Hi. i came across opencart today from opensourcecms and liked it.
downloaded , installed and when i thought about customizing template i was greeted by strange template language, strange for me as i have never used smarty or any other template engine.
i Google about it but could not find any documentation about your template system.
can somebody give me a crash course about template system used by opencart?
i checked smarty tutorial but figured out that it is not smarty as first thing tutorial advised to download smarty in libs and include smarty.php.
i searched whole opencart folder and did not find a single smarty reference.
please help
Re: which template engine used?
Posted: Wed Jul 22, 2009 5:54 pm
by JNeuhoff
Opencart uses its own Model-View-Control design. The templates are part of the View portion, and you'd find them as the /catalog/view/.../*.tpl files on an installed Opencart system. The *.tpl files are all part of a composite view and uses simple PHP-variables as placeholders for the dynamic bits of the HTML templates. These variables are set in the corresponding controller PHP files, found in the catalog/controller/.../*.php files.
Re: which template engine used?
Posted: Wed Jul 22, 2009 6:01 pm
by Daniel
I used the most simplist I could find.
Code: Select all
<?php
final class Template {
protected $data = array();
public function set($key, $value) {
$this->data[$key] = $value;
}
public function fetch($filename) {
$file = DIR_TEMPLATE . $filename;
if (file_exists($file)) {
extract($this->data);
ob_start();
include($file);
return ob_end_flush();
} else {
exit('Error: Could not load template ' . $file . '!');
}
}
}
?>
Re: which template engine used?
Posted: Wed Jul 22, 2009 6:13 pm
by readyman
Re: which template engine used?
Posted: Wed Jul 22, 2009 7:28 pm
by Qphoria
the template language is called "php".
I never will understand smarty.
Normal php:
Code: Select all
<? foreach ($myArray as $foo) { ?>
<li><? echo $foo; ?></li>
<? } ?>
Smarty:
Code: Select all
{foreach from=$myArray item=foo}
<li>{$foo}</li>
{/foreach}
There is actually MORE typing there, and it doesn't look any cleaner to me.
Re: which template engine used?
Posted: Wed Jul 22, 2009 7:36 pm
by phpuk
I agree with Qphoria,
Smarty is bloated and is basically a re-write of lots of standard PHP code so when you use it you have to learn two different versions of syntax one for PHP and one for Smarty which is still basically PHP.
Why???
I just don't get it!
Stick with PHP and forget about Smarty altogether.
Phil.
Re: which template engine used?
Posted: Wed Jul 22, 2009 9:31 pm
by noescape
thanks all for your help.
i never liked smarty when i first got a chance to learn it and forgot about it.
but when i checked template files i got confused because it was neither complete php nor smarty. but it looks much simpler than smarty.
now after going through the replies i got the idea.
i will study the whole model again and will be back with more questions.
thanks
Re: which template engine used?
Posted: Wed Jul 22, 2009 9:37 pm
by Qphoria
Of course its php.. its just php and thats all. Hence the <?php xxxxx ?> surrounding tags.
Any php you can type, it will take it.
Re: which template engine used?
Posted: Sat Nov 10, 2012 5:47 pm
by dulton
I m new to open cart can any one help in cutomizing the template
Re: which template engine used?
Posted: Tue Jun 07, 2016 6:29 am
by Chris_UK
I understand that php is essentially a templating language and display / logic can be separated already.
Smarty:
Code: Select all
<table>
<tr>
{foreach from=$myArray item=foo}
<td>{$foo}</td>
{if foreach.foo.iteration is div by 4}
</tr>
<tr>
{else if foreach.foo.last}
</tr>
{/if}
{/foreach}
</table>
I believe there is also an else available for foreach in smarty.
Now in pure php you have this more tedious code. (IMO).
Code: Select all
<table>
<tr>
<?php
$len = count($array);
$i = 1;
foreach ($array as $key => $val) {
echo "<td>{$key} {$val}</td>";
// ive used braces for cleaner code here to save concatenation.
if ($len / $i === 0 && $i !== $len && $len !== 0) {
echo "</tr><tr>";
}
if ($i === $len) {
echo "</tr>";
}
$i++;
} ?>
</table>
Re: which template engine used?
Posted: Tue Jun 07, 2016 1:25 pm
by Burt65
Chris, this topic is 7 years old???? Did you check the date
