I am trying to setup additional page and category layouts in Opencart 1.5.4.
I have got to a stage where if I enter the route of the new category into the address bar, the new template shows as I want, but I don't seem to be able to register that route change in OC.
If I specify the change in the .htaccess file the new template loads as expected, but I don't this is the right answer to the problem (although it works).
Addition to .htaccess (not correct method I'm sure)
RewriteRule ^skis$ index.php?route=product/categories&path=1 [L,QSA]
I have created two new files
/catalog/view/theme/default/template/product/categories.tpl
/catalog/controller/product/categories.php
In /catalog/controller/product/categories.php, I have changed the content to reflect new tpl file;
class Controllerproductcategories extends Controller {
.
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/categories.tpl')) {
$this->template = $this->config->get('config_template') . '/template/product/categories.tpl';
} else {
$this->template = 'default/template/product/categories.tpl';
}
So in summary
If I specify the rewrite in the .htaccess file the layout loads, if I don't it doesn't.
I have added a new layout in OC and selected it against the category
Anyone got any ideas I might try to get this working correctly? I have a load of templates to create for products, categories and information pages so would like to do this correctly.
Tx in advance
Stu
I opted for this approach in the end.. might help someone else.
if ($this->data['heading_title'] == "Skis") {
$this->template = $this->config->get('config_template') . '/template/product/categories.tpl';
} elseif ($this->data['heading_title'] == "Softgoods") {
$this->template = $this->config->get('config_template') . '/template/product/category.tpl';
} elseif ($this->data['heading_title'] == "Outlet Store") {
$this->template = $this->config->get('config_template') . '/template/product/category.tpl';
} else {
$this->template = $this->config->get('config_template') . '/template/product/category.tpl';
}
From what I can see, you're trying to hard code each individual template and it's not really going to work in the way you've chosen using layouts for the category. Layout's are designed to arrange content on a page rather than specify templates
I've actually created a commercial version of what you are trying to achieve which can be found here. It allows you to create templates and assign it to one or more pages. It works for products, categories, manufacturers and information pages. It also allows you to specify the template for products under a whole category or manufacturer too
Related
I am following the book OpenCart Theme and Module development
In chapter 3 it states:
For example, you can refer to catalog/controller/account/account.php. You
will find the following code in it:
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/account.tpl')) {
$this->template = $this->config->get('config_template') . '/template/account/account.tpl';
} else {
$this->template = 'default/template/account/account.tpl';
}
However, it is not possible to find this code excerpt while checking catalog/controller/account/account.php.
Where is this check in OpenCart 2.3?
Loading view in OpeCart 2.3:
$this->response->setOutput($this->load->view('account/account', $data));
You may want to ckeck these files:
system\library\response.php
system\engine\loader.php
system\library\template.php
I have created header_top.tpl in the catalouge folder (down in the theme "common" folder) and then a controller in the controller folder. But I do not know how should I render a template with a controller (and send data from controller to the template to be further parsed by the template).
I know $this->render() does render the template but what happens before to it is vague to me.
There should be a condition similar to the below the code in your controller file. Replace with your template file in that section as given below:
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/header_top.tpl')) {
$this->template = $this->config->get('config_template') . '/template/common/header_top.tpl';
} else {
$this->template = 'default/template/common/header_top.tpl';
}
Values set as $this->data['sitename'] = 'stackoverflow'; in controller file can be used in template file like echo $sitename;
Have a nice day !!
I'm new to opencart. my opencart system was working fine. but suddenly i got a error. it said Notice: Error: Could not load template C:\wamp\www\suprize/catalog/view/theme/default/template/module/featured_category.tpl! in C:\wamp\www\suprize\system\engine\controller.php on line 91 what is this and what is the reason to come this error. ?
Goto your catalog/controller/module/featured_category.php
check the following code lines below as overview there to get idea try to check spell also
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') .
'/template/module/featured_category.tpl')) { $this->template =
$this->config->get('config_template') .
'/template/module/featured_category.tpl'; } else { $this->template =
'default/template/module/featured_category.tpl'; }
then goto to the folder
catalog/view/theme/default/template/module/
find the same file as defined above e.g featured_category.tpl also check spelling of file name. A suggestion is to upload this extension again :) that will also fix your problem
Check the following notes:
catalog/view/theme/default/template/module/featured_category.tpl - Does this file exists?
verify the file permission.
Check the file path.
Usin joomla 3.1 with SEF and mod rewrite.
How can I get the link of the menu item that a "menu item alias" references ?
Using the code below renders the alias field of the menu items alias and not the "menu alias" destination.
$menu->getItem($men->id)->route
I don't think this would be the best approach but you could load this from the database, for example...
$menuLink=""; //to be used to store the result of our query
$alias='somealias'; //I am guessing you will already have the alias ready from some source
//query the database to find the link corresponding to this alias
$db=JFactory::getDbo();
$query=$db->getQuery(true);
$query->select('link');
$query->from('#__menu');
$query->where("alias='" . $alias . "'");
$db->setQuery($query);
try
{
$result=$db->loadObject();
$menuLink=$result->link;
}
catch(RuntimeException $e)
{
JError::raiseError(500, $e->getMessage());
}
If someone comes up with a better way then that would also be good :) This is how I usually do it though, it works fine for me. Hope this helps.
I am very new to opencart but I think this is easy and best solution out there. Although playing with templates is not a joy...
I am struggling to create some additional template pages. For example I have two types of products and category pages. I want to different templates for different products. In opencart you have only one layout for products.
What I thought to do is to make a duplicate of product layout. I got some help online but I am still not sure what more is needed. This is what I've done so far...
1 - Copy the controller file of catalog/controller/product/product.php and changed to catalog/controller/product/product-2.php. Then I changed this in controller:
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product-2.tpl')) {
$this->template = $this->config->get('config_template') . '/template/product/product-2.tpl';
} else {
$this->template = 'default/template/product/product-2.tpl';
}
2 - Then I copied the product language file and save as product-2
3 - After that I copied the actual tpl file and save as product-2
It was looking fine but if I try to make some changes to product-2.tpl nothing changes. Do I have to copy some more files to complete it?
After search and doing lot of research and mind-boggling, i found a very useful method to do what i want to do. in this way i have fully control of the opencart theme system. i can make as many different layouts as i wanted. i dont have to use VQmod neither have to make any controller but you have to use the existing controllers like product, category etc. if you are making your own controller even then it works.
here are the steps to follow to achieve different template for different categories, products and common pages.
i am here doing the example of products.
1- create custom template of product in product folder of the theme. e.g customproduct.tpl
2- now customize it as you wanted.create a product and take the id of it. id is very important here.
3- go to the controller catalog/controller/product/product.php
4- find this code
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product.tpl')) {
$this->template = $this->config->get('config_template') . '/template/product/customproduct.tpl';
} else {
$this->template = 'default/template/product/product.tpl';
}
5- now you have to use the simple if else condition. for example
//42 is the id of the product
if($this->request->get['product_id'] == 42){
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/customproduct.tpl')) {
$this->template = $this->config->get('config_template') . '/template/product/customproduct.tpl';
} else {
$this->template = 'default/template/product/customproduct.tpl';
}
}
else{
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product.tpl')) {
$this->template = $this->config->get('config_template') . '/template/product/product.tpl';
} else {
$this->template = 'default/template/product/customproduct.tpl';
}
}
that's it job Done ;)
you can do the same thing for other controllers.
As you can see here ;
http://pranshuarya.com/jaal/Development/opencart-creating-a-new-viewtemplate.html
This was the second option of the real solution for "completely new layout" request.
Both can be used. Your solution is time saver if you will not need a new controller routine.But that way is more flexible.
Here are the steps ;
Add a new controller file to /catalog/controller. call something like new_layout.php... copy if there is a similar controller already. Be sure to change controller name as i told in my comment below.
Add a new view file in your theme folder ... like controller if you wish you can copy a simiplar view files content and modify as you wish.
Add the new layout either from admin panel System/Design/Layouts or from MYSQL table directly as explained in the link above.
It's ok now. Just add some modules in this layout view and enjoy.