I am new to OpenCart, and I would like to apply my theme to OpenCart.
I know I should not edit the default template directly, but how do I copy the default template files and alter it to apply the theme?
Balan, you can start by copying the folder catalog\view\theme\default and all of it's subfolders files etc.
So the copy will be your new theme. So let's say you now have these folders
catalog\view\theme\default
catalog\view\theme\my-new-theme
Go to the Admin site and select System > Settings
On the "Store" tab you should see the options "default" and "my-new-theme" as options for the field named "Template". Select "my-new-theme" and save.
Start making changes to the files under catalog\view\theme\my-new-theme and they'll appear straight away
Create a custom theme in opencart:
Opencart use fallback function, it's mean that when opencart doesn't found certain template in your theme, it will find on default theme folder. So to make a new theme, you doesn't need to copy all file from default theme. But, building a theme not just about make new folder theme and change it color. In this tutorial we will learn basic understanding on how controller and model work, it's related to template modification.
Before we continue, I want to make it clear that theme in this tutorial is refer to the theme inside theme folder (catalog/view/theme/mytheme) and template refer to .tpl file inside the template folder (catalog/view/theme/yourtheme/template).
Step 1. Build "Very" Basic Theme
Create new folder mytheme on catalog/view/theme/, the folder tree will be like this:
catalog/view/theme/
|-> default
|-> mytheme
Now go to Admin -> System -> Setting - > Edit Store ->Tab Store -> template -> mytheme.
Refresh your frontpage. Maybe your site litle bit mess, but your new theme is work!! :)
Step 2. Basic Theme
Make folder and copy some files from default theme, but DO NOT copy all files. Follow this folder tree:
catalog/view/theme/
|-> default
|-> mytheme
|-> image/*.* - copy all image
|-> stylesheet/*.* - copy all stylesheet
|-> template
|-> common
|-> header.tpl
Note:
We need to copy all the images because it's required by stylesheet.css.
We need to copy IE stylesheet since it's declared on header.tpl (remove the file when you removing the IE style at header.tpl)
We neet to copy slideshow.css and carousel.css since it's needed by opencart module.
Rating star image is hard-coded into Page: category, manufacturer_info, product, review, search, special; Module: bestseller, featured, latest, special. It's up to you whether including those module and page to your theme and used another rating image, or just replacing use default rating star image.
Now open header.tpl with text editor.
Search word default and replace with mytheme
Refresh your frontpage, and everything should be the same as when you used the default theme.
To get different visual like changing color etc, you can modificate mytheme/stylesheet/stylesheet.css
Step 3. Customizing Template (1): Understanding Controller
What template (*.tpl) is need to customize for a "good theme" ? Well, the answer is relative. In step 2 we already and only customizing the header.tpl. The most important rule to remember is never edit default theme template. Copy what you need to your theme folder, see example bellow.
catalog/view/theme/
|-> default
|-> mytheme
|-> image
|-> stylesheet
|-> template
|-> common
|-> header.tpl
|-> footer.tpl|-> information
|-> information.tpl|-> product
|-> product.tpl
|-> category.tpl
|-> manufacturer_list.tpl
To customizing template and work with the controller, you need to understand that opencart used push-based MVC model -CMIIW.
In quick explanation:
When you accessing route=product/category url, opencart call controller/product/category.php file.
This controller (ex. category.php) will decide which MV-L: Model, View (tpl), language will be load. In category controller (category.php) load:
3 Model (category, product, image): $this->load->model('...');
2 View (category.tpl & not_found.tpl): $this->template = '...';
1 Language: $this->language->load('...')
The controller also decide what data will be pushed into template and how user input will be processed.
$this->$this->data['text_price'] = $this->language->get('text_price'); will produce Price in template: <?php echo $text_price; ?>
When you change the product show (from 15 to 25) at frontpage, controller catch the request with if (isset($this->request->get['limit'])) { ... } then process it $this->data['limits'][] = array(... 'value' => 25, ...);
Remember that there is no fallback function for controller. If you modificate the controller file manually, it will be replaced when you upgrade the opencart. Instead modificate it manually, you can used vQmod to make "virtual modification". We will talk this on step 5.
Step 4. Customizing Template (2): Understanding Model
A Model in MVC in charge to pull and push data to database. Before controller get or post a data through model, the spesific model need to be loaded.
load model: $this->load->model('catalog/product');
get data: $this->model_catalog_product->getTotalProducts()
post data: $this->model_catalog_product->editProduct()
$this->load->model('catalog/product') tell the opencart to load model/catalog/product.php either in admin or catalog controller. getTotalProducts(), editProduct() is a function inside the model/catalog/product.php.
Now open model/catalog/product.php and find public function getProduct.
See list after return array, and you will found all product data.
The question is, if the getProduct() listed all product data, why it doesn't show at category page (frontpage)? This because the category controller decide not to show all data.
Open controller/product/category.php, find $this->data['products'][] = array to see what product data is used by controller.
Step 5. Customizing Template (3): Understanding vQmod
vQmod is a virtual modificate and usually used to make some change to non-fallback file like controller and model without modificating the default file.
You can download latest version and read further explanation about vQmod here.
To install vQmod, copy vqmod folder inside the package to opencart root.
yoursite
|-> admin
|-> catalog
|-> download
|-> image
|-> system
|-> vqmod
Go to your browser and access: http://localhost/yoursite/vqmod/install. You will see success message: vQmod has been installed on your system!
On the vQmod package, you will see folder docs and example to give you a refference how vQmod work. Here I will give you some quick refference:
vQmod File is an .xml file stored at vqmod/xml folder. When executed, the vQmod force opencart to use the modification instead the default file (original file) and produce cache file at vqmod/vqcache.
One vQmod File able to modificate multiple file; within one file, vQmod able to do multiple modificate operation.
Example structure inside a vQmod File:
<modification>
<id>vQmod File ID</id>
<version>1.0.0</version> --> vQmod File version
<vqmver>1.0.8</vqmver> --> minimum vQmod version to work
<author>your name</author>
<file name="catalog/controller/product/category.php "> --> the file to modify
<operation>
<search position="replace"><![CDATA[
search this code and replace it with code bellow
]]></search>
<add><![CDATA[
add this new code to replace code above
]]></add></operation>
<operation>
<search position="after"><![CDATA[
search this code and add code bellow after it
]]></search>
<add><![CDATA[
add this new code after code searched above
]]></add></operation></file>
<file name="...">
<operation>
<search position="before"><![CDATA[
search this code and add code bellow before it
]]></search>
<add><![CDATA[
add this new code before code searched above
]]></add></operation></file></modification>
Remember that all the files in the view ends with a .tpl extension.
The variables values in the tpl files comes from their respective controllers. Whereas the variables values in the controller comes from the model, which fetches the data from the database.
So if you make any changes to the variable name in the tpl files change the variable name in the respective controller files also.
#JackLB - You can name template files as you wish. Every template is anyway specified manually in controller file.
Try to search for .tpl in any controller file, and you will see:
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') .
'/template/common/header.tpl')) {
$this->template = $this->config->get('config_template') .
'/template/common/header.tpl';
} else {
$this->template = 'default/template/common/header.tpl';
}
Opencart searches for template in custom template folder. If not found, it falls back to default template. If not found, error will be shown.
Change the location path accordingly.
But this is more sophisticated - to use the same naming for controller/template.
Related
I am working with Bitrix24. I want to customise the component and module of Bitrix24.
But I didn't have the standard documentation for this.
Some one help me for the same,how we can work with local folder for customise component and module etc.
If you need to change logic of component you may do through this way:
create the local folder in your documet_root path
create components folder in the local folder
create bitrix folder in the components folder
copy component folder from /bitrix/components/bitrix to
/local/components/bitrix
edit logic in the component.php file (or in class.php file if
component using new bitrix core - D7) in the copied folder
If you need to change only the view, this is another way:
Instead of creating the /local/components/bitrix you have to
create /local/templates/.default/ folder
Copy there only the .default template of a needed component
Edit template.php file
With the second way, you also may change (or rich it) some data in final $arResult array provided for the template.php, just create result_modifier.php file in the template directory.
You can find this and other information in the free course Bitrix Framework, pay attention to this link, it will be very helpful
I create new custom theme by copy paste default theme of Opencart 2.3.0.2 and rename it but this theme is not display in admin panel->System->Settings and Your Store (Default)=> 'Edit'. Anybody can help me this regard.
Thank you anticipation .
I have got answer.
Extensions >> Themes (Select From Dropdown) >> Edit (Your Theme) >> Theme Directory (Select Your theme in dropdown and press Save).
Your theme will be changed.
Previous answered deleted. Here is a link (and instructions from it):
http://undefined.gr/site/2016/10/09/custom-opencart-2-3-0-2-theme/
Copy folder upload/catalog/view/theme/default ->
upload/catalog/view/theme/mytheme
Copy file
upload/admin/controller/extension/theme/theme_default.php ->
upload/admin/controller/extension/theme/mytheme.php
Change class name in the file mytheme.php from ControllerExtensionThemeThemeDefault to ControllerExtensionThemeTFM
(line 2).
In mytheme.php replace all “theme_default” text to “mytheme“.
Copy file upload/admin/view/template/extension/theme/theme_default.tpl to
upload/admin/view/template/extension/theme/mytheme.tpl
In mytheme.tpl replace all “theme_default” text to “mytheme“.
Copy file upload/admin/language/en-gb/extension/theme/theme_default.php
to upload/admin/language/en-gb/extension/theme/mytheme.php.
In mytheme.php change the theme title (line 3).
Rename file upload/catalog/view/theme/mytheme/image/default.png to mytheme.png.
In the 2.3.x version is a bit more complicated. The following is a step by step.
Download the files.
admin/controller/theme/theme_default.php
admin/language/english/theme/theme_default.php
admin/view/template/theme/theme_default.tpl
catalog/view/theme/default/* //Download the entire folder
Rename files from the folder admin/* of theme_default to "theme_custom".
Rename the folder catalog/view/theme/default to custom
Open the file admin/controller/theme/theme_default.php and replace all words default to custom.
Create a folder called upload and move all the folders downloaded in step 1 into it.
Zip and rename it to custom.ocmod.zip and send through the OC installer.
left.phtml the file that displays the left navigation on a magento page is only showing on one list view page and not the others does anyone have a solution to get that file to show in all list views
If you are tasking left.phtml,
Then According magento structure left.phtml are only show for Non-Anchor category in it left side of category.
And layer navigation are only showing for Anchor category.for anchor left.phtml is not showing.
For non-Anchor categories
see catalog.xml code
<catalog_category_default translate="label">
<label>Catalog Category (Non-Anchor)</label>
<reference name="left">
<block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/>
</reference>
Also for
Anchor categories
see at catalog.xml
<catalog_category_layered translate="label">
<label>Catalog Category (Anchor)</label>
<reference name="left">
<block type="catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/view.phtml"/>
</reference>
Hope ,you will understand.
Check the layout in folder theme/package (it can be in default/default, when your theme is in another folder)
Check if layout is plugged (use in your layout.xml something like <remove name="header">). If header will be removed - you use correct layout
Check the handle and reference name, where you are adding block. For example: you are adding layered navigation block. On one page it placed in handle <catalog_category_layered>, but your page there no this handle. Try to add to <catalog_category_default> or even in <default>.
Open your template and check if the block was added there. Look for
<?php $this->getChildHtml('blockName'); ?>
Try to change your block name (maybe on this page already exist block with the same name)
(this option can be useless for you) Please check the block output in system / configuration / advanced
Maybe there is a conflict between two navigation modules (for example module A and module B). The module A can use it for rewrite. But the module B will use it only for investigation and use on this page it's own calls. In that case the module A will not work (to resolve this issue you need to change rewrite. class A should rewrite class B)
If you are trying to add navigation to CMS page - try to google this topic (how to add navigation to CMS page). There are many examples and I don't want to duplicate them.
I cannot figure out how to add additional plugins and Templates to a ckeditor config in rails 3 (asset pipeline).
I tried to put all of them into two folders that i created:
/app/assets/javascripts/ckeditor/plugins
app/assets/javascripts/ckeditor/templates
...without success.
What is the correct way to add ckeditor templates and plugins in rails3?
I'm on
ruby 1.9.3p362
Rails 3.2.11
----------- UPDATE
Now I create a template (starting from a copy of default.js ckeditor template) in
app/assets/javascripts/ckeditor/plugins/templates/templates/template.js
and added in the config.js of CKEDITOR:
config.templates_files = [ '/plugins/templates/templates/template.js' ];
But I can't access to template
this is an old question but for what is worth i will give my answer:
I dont think there is a correct way to add the templating to the asset pipeline, since on deployment it will get compresed and your file will be gone.
what I did was i add my template.js to my public folder in rails like this:
public -> templates -> template.js
and on my ck config file I added this line:
config.templates_files = [ '/templates/template.js' ];
also if you want to add the images for the templates:
public -> templates -> images
and in your template.js file add this line:
imagesPath : '/templates/images/'
hope it helps.
I am a beginner php and joomla user. I have installed jumi component in joomla 2.5. I want to collaborate between pages but I don't know how to link between them. Can anyone please help me by explaining briefly.
Such as I have created a new file in jumi named "linked to another article" and the codes are explained below:
I have defined them:
defined("_JEXEC") OR die ("Restricted access");
I have created a link:
$linktext = "<Click> & you'll see";
After that I put the href:
<a href="FILE PATH"><?php echo htmlspecialchars($linktext);?>
After that I have created another file in jumi named "ABC" where I put <?php echo"Hello World"?>, how can I include the path of ABC file in the "FILE PATH" of my first file so that if I click on the first files link then it will redirect me to my ABC file and show "Hello World"?
I will be grateful for your kind reply.
Thanks.
Let's suppose you have 2 files in the jumi directory (components/com_jumi/files). A.php and B.php.
We don't want people to be able to access those files directly, so we place inside them the snippet
defined("_JEXEC") OR die ("Restricted access");
So far so good. Assuming that your website's URL is h**p://www.example.com, you'll get a
restricted access if you try any of the bellow:
h**p://www.example.com/components/com_jumi/files/A.php or
h**p://www.example.com/components/com_jumi/files/B.php.
This means that you cannot use those URLs to access for example B.php from A.php.
So here is a workaround:
Create 2 jumi applications from your administration panel, one for A.php (let's call it Application_A) and one for B.php (let's call it Application_B). I supose you have already done that.
Create a menu item of type Jumi application, point it to Application_A and use as its alias the application_a. From this point A.php its accesible as h**t://www.example.com/application_a
Create a new Joomla menu (you can call it hidden for clarity), and in that menu create a menu item of type Jumi application, point it to Application B and use as its alias the application_b. From this point B.php its accesible as h**t://www.example.com/application_b
So. whenever you want to access B.php from A.php you can do it simply as
Go to B