Post by noescape » Wed Jul 22, 2009 2:50 pm

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

Newbie

Posts

Joined
Wed Jul 22, 2009 7:31 am

Post by JNeuhoff » Wed Jul 22, 2009 5:54 pm

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


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by Daniel » Wed Jul 22, 2009 6:01 pm

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.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by readyman » Wed Jul 22, 2009 6:13 pm

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


User avatar
Global Moderator

Posts

Joined
Wed May 20, 2009 5:16 am
Location - Sydney

Post by Qphoria » Wed Jul 22, 2009 7:28 pm

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.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by phpuk » Wed Jul 22, 2009 7:36 pm

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.

Global Moderator

Posts

Joined
Wed Mar 25, 2009 10:57 am

Post by noescape » Wed Jul 22, 2009 9:31 pm

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

Newbie

Posts

Joined
Wed Jul 22, 2009 7:31 am

Post by Qphoria » Wed Jul 22, 2009 9:37 pm

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.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by dulton » Sat Nov 10, 2012 5:47 pm

I m new to open cart can any one help in cutomizing the template

Newbie

Posts

Joined
Sat Nov 10, 2012 5:46 pm

Post by Chris_UK » Tue Jun 07, 2016 6:29 am

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>

New member

Posts

Joined
Wed Jan 20, 2016 4:39 am

Post by Burt65 » Tue Jun 07, 2016 1:25 pm

Chris, this topic is 7 years old???? Did you check the date ???

Over 95% of all computer problems can be traced back to the interface between the keyboard and the chair...


User avatar
Active Member

Posts

Joined
Mon Nov 18, 2013 3:23 pm
Location - Oz
Who is online

Users browsing this forum: No registered users and 24 guests