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
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
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.
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
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 . '!');
}
}
}
?>
OpenCart®
Project Owner & Developer.
Check out this post which explains the framework - http://www.opencart.com/forum/viewtopic.php?f=20&t=4113
http://www.alreadymade.com
Follow me on twitter.com/alreadymade
the template language is called "php".
I never will understand smarty.
Normal php:
Smarty:
There is actually MORE typing there, and it doesn't look any cleaner to me.
I never will understand smarty.
Normal php:
Code: Select all
<? foreach ($myArray as $foo) { ?>
<li><? echo $foo; ?></li>
<? } ?>
Code: Select all
{foreach from=$myArray item=foo}
<li>{$foo}</li>
{/foreach}
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.
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.
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
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
I understand that php is essentially a templating language and display / logic can be separated already.
Smarty:
I believe there is also an else available for foreach in smarty.
Now in pure php you have this more tedious code. (IMO).
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>
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>
Who is online
Users browsing this forum: No registered users and 24 guests