Please some one tell me how can I position modules like slider or banner in header or how can we define additional regions for the modules.
Well, I am working on it.
Firstly, you should add a new position in the admin page.
Which means you should change three files and add some lines into each.
For example, if you want to add slideshow into header, you should add a new position in
$this->data['text_header'] = $this->language->get('text_header'); // in admin/controller/slideshow.php
////////////////////////////////////////////////
$_['text_header'] = 'Header'; // in admin/language/slideshow.php
////////////////////////////////////////////////
<?php if ($module['position'] == 'header') { ?> // in admin/view/slideshow.tpl
<option value="header" selected="selected"><?php echo $text_header; ?></option>
<?php } else { ?>
<option value="header"><?php echo $text_header; ?></option>
<?php } ?>
Then a new position for slideshow has been defined. and you can choose it in the admin page.
After that, you should add those codes in catalog/view/header.tpl
<?php foreach ($modules as $module) { ?>
<?php echo $module; ?>
<?php } ?>
Then, in the catalog/controller/header.php, add some codes like content_top.php does:
$layout_id = 1;
$module_data = array();
$this->load->model('setting/extension');
$extensions = $this->model_setting_extension->getExtensions('module');
foreach ($extensions as $extension) {
$modules = $this->config->get($extension['code'] . '_module');
if ($modules) {
foreach ($modules as $module) {
if ($module['layout_id'] == $layout_id && $module['position'] == 'header' && $module['status']) {
$module_data[] = array(
'code' => $extension['code'],
'setting' => $module,
'sort_order' => $module['sort_order']
);
}
}
}
}
$sort_order = array();
foreach ($module_data as $key => $value) {
$sort_order[$key] = $value['sort_order'];
}
array_multisort($sort_order, SORT_ASC, $module_data);
$this->data['modules'] = array();
foreach ($module_data as $module) {
$module = $this->getChild('module/' . $module['code'], $module['setting']);
if ($module) {
$this->data['modules'][] = $module;
}
}
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';
}
$this->render();
Then all done.
The only problem for this code is the slideshow cannot display as a slideshow but a static picture or pictures.
Wish you could solve it out and reply to me.
My question post:
Opencart developement: change slideshow's position
do what Huawei Chen wrote and then add these to header:
<script type="text/javascript" src="catalog/view/javascript/jquery/nivo-slider/jquery.nivo.slider.pack.js"></script>
<link rel="stylesheet" type="text/css" href="catalog/view/theme/default/stylesheet/slideshow.css" media="screen" />
and slider will be working
You can learn from controller/common/column_right.php
Check module position (line 50), you can adapt it to "header":
$module['position'] == 'column_right'
Set the output (line 69), you can adapt it to something like "header_mod" :
$this->data['modules']
You need to modificate module at admin to show additional module position.
There is no "header" module position options at admin page.
You can also use an extension that places 2 positions in header and footer. It create the same hooks, like column_left and content_top, etc.
it works with VQmod for opencart 1.5x
I think this extension will make your life super simple. http://www.opencart.com/index.php?route=extension/extension/info&token=extension_id=14467
You can add unlimited number of positions to your header, add columns and change there width all through admin
Regards
This guide helped me:
http://www.mywork.com.au/blog/create-new-module-layout-position-opencart-1-5/
I was using 1.5.6.1 Opencart version.
I read all of your answer. Forget all things.
It's very easy to call any module into header section.
Open your catalog/controller/common/header.php file
$this->data['YOUR_MODULE_NAME'] = $this->getChild('module/YOUR_MODULE_NAME');
Now Open .tpl file of header, which is located at
catalog/view/theme/YOUR_THEME/template/common/header.tpl
and echo your desire module whenever you want, like as:
<?php echo $YOUR_MODULE_NAME;?>
That's it. you are done.
You must know that your new position is a new child.
file: catalog/controller/common/header.php
$this->children = array(
'module/language',
'module/currency',
'module/cart'
);
add your new position, like this:
$this->children = array(
'common/content_new',
'module/language',
'module/currency',
'module/cart'
);
now you can echo your new position in your header.tpl
Related
I am using EasyMDE text editor on my Notemaking website, but for some reason, the uploadImage functionality doesn't work.
This is how I instantiate EasyMDE.
var easyMDE = new EasyMDE({
autofocus: true,
autorefresh: true,
spellChecker: false,
minHeight: '180px',
uploadImage:true,
});
Can some one help me fix this issue or point me in the right direction of how to solve it?
I was searching for a PHP method but this is what I got :
https://github.com/Ionaru/easy-markdown-editor/pull/71
Edit:-
I figured it out in PHP
You need to also set the "imageUploadEndpoint" value to another file and save your image and print json.
This is how I did in PHP.
Client-Side:
var easyMDE = new EasyMDE({
uploadImage:true,
imageUploadEndpoint: 'upload.php'
});
Server-Side(in upload.php):
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
header('Content-Type: application/json');
//logic for saving the file
if(image_saving_successful)
{
$url = the_filepath_for_the_image_saved
echo '{"data": {"filePath": "'.$url.'"}}';
http_response_code(200);
exit;
}else{
echo '{"error": "your_error_message"}';
http_response_code(400);
exit;
}
}else{
header('location: index.php');
exit;
}
?>
There are different response code for different error messages. Check Readme.md
I've created some if / else statements to get a download when a user hit click
but dont work ,because you can direct download without field name or email ,please help me
contact. php for my site
http://my-easy-woodworking-projects.com
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$mail_to = 'lulu#yahoo.com';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script>
var str = "download";
document.write(str.link("http://www.myshedplans.com/12BY8SHED.pdf"));
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to gordon#template-help.com');
window.location = 'contact_page.html';
</script>
<?php
}
?>
I'm not quite sure why that if/else isn't working for you but one thing that can happen is the interpreter forgets about the if statement when it gets down to the else. A way to get around this is by echoing your html code within the conditional block like bellow:
<?php
if ($mail_status) {
echo "<script>";
echo "var str = \"download\";";
echo "document.write(str.link(\"http://www.myshedplans.com/12BY8SHED.pdf\"));";
echo "</script>";
}
else {
echo "<script language=\"javascript\" type=\"text/javascript\">";
echo "alert('Message failed. Please, send an email to gordon#template-help.com');";
echo "window.location = 'contact_page.html';";
echo "</script>";
}
?>
I want to display the currency list on the product description page. How can I do that?
I copied the code from header.tpl () and pasted it in the product.tpl but I get an error:
Notice: Undefined variable: currency in C:\xampp\htdocs\mysite.com\catalog\view\theme\mytheme\template\product\product.tpl on line 60.
I tried adding the following code in product.tpl.
<?php include(DIR_APPLICATION.'\view\theme\mytheme\template\module\currency.tpl');
but that did not work either. Please help as I want to get this working.
controller/common/header.php function index() add in to:
$this->data['mygetcurrency'] = $this->currency->getCode();
catalog\view\theme\default\template\common\header.tpl add in to:
<?php echo $mygetcurrency; ?>
//EUR
i guess this can be the easiest way.
<?php echo $this->currency->getSymbolRight($this->session->data['currency']) ?>
OR
<?php echo $this->currency->getSymbolLeft($this->session->data['currency']) ?>
The best will be to do like this
$this->load->model('localisation/currency');
$this->data['allcurrencies'] = array();
$results = $this->model_localisation_currency->getCurrencies();
foreach ($results as $result) {
if ($result['status']) {
$this->data['allcurrencies'][] = array(
'title' => $result['title'],
'code' => $result['code'],
'symbol_left' => $result['symbol_left'],
'symbol_right' => $result['symbol_right']
);
}
}
thanks
The $currency variable is built by the /catalog/controller/module/currency.php controller, which is normally called by /catalog/controller/common/header.php (using $this->children array).
To display this element in the product template, you'll need to call on this controller (and its view) using the $this->children array of the product controller (/catalog/controller/product/product.php). In opencart 1.5.4.1, it's around line 362
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header',
'module/currency' // Just add this line
);
Unfortunately, this will display the currency element at the top of the page by default, because this element's style is set to absolute positioning. You'll need to edit /catalog/view/theme/*/template/module/currency.tpl to make the HTML and CSS a bit more flexible.
you can use very simple code. add this in your controller file.
$data['currency-symbol'] = $this->currency->getSymbolLeft($this->session->data['currency']);
And now you can echo it in your related .tpl file using this
<?php echo $currency-symbol ;?>
It there a way to read everything from within a language with Opencart?
At the moment I have to:
Controller
$this->load->language('help');
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['tab1'] = $this->language->get('tab1');
Language File
<?php
// Heading
$_['heading_title'] = 'Help';
$_['tab1'] = 'Account';
?>
The easiest thing to do is to use array merge at the top of your controller
$this->data = array_merge($this->data, $this->language->load('language/file'));
or simply
$this->data += $this->language->load('language/file');
Edit
For 2.x, use
$data = array_merge($this->data, $this->language->load('language/file'));
3.x does this automatically
In system/library/language.php is a
function to get everything called all().
This is how to get a single item:
$var = $this->language->get('heading_title');
This returns an array with all language entries:
$var = $this->language->all();
Is there any way to load view 'header'/'footer' without calling $this->load->view('header') or $this->load->view('footer') in every controller? Maybe a template that can be use in every view?
Here are a couple simple approaches to get you started:
Create a template class:
class Template {
function load($view)
{
$CI = &get_instance();
$CI->load->view('header');
$CI->load->view($view);
$CI->load->view('footer');
}
}
Usage in controller:
$this->template->load('my_view');
Use a master view file:
<!-- views/master.php -->
<html>
<header>Your header</header>
<?php $this->load->view($view, $data); ?>
<footer>Your footer</footer>
</html>
In the controller:
$this->load->view('master', array(
'view' => 'my-view-file',
'data' => $some_data
));
I prefer the Template class approach, as it's easy to add methods to append templates areas, load javascript files, and whatever else you need. I also prefer to automatically select the view file based on the method being called. Something like this:
if ( ! isset($view_file)) {
$view_file = $CI->router->fetch_class().'/'.$CI->router->fetch_method();
}
This would load views/users/index.php if the controller is Users and the method is index.
You need to load view files somehow, this the way CI use to include the files.
Stick to the standard, I think it's the best practice.
Make a function that loads header and footer and places data in between.
Anyway the model on which CI is built requires the explicit loading of views (afaik).
I usually extend CI's Loader class to accomplish this...
<?php
class MY_Loader extends CI_Loader {
public function view($view, $vars = array(), $return = FALSE, $include_header = TRUE, $include_footer = TRUE)
{
$content = '';
if ($include_header)
{
$content .= parent::view('header', $vars, $return);
}
$content .= parent::view($view, $vars, $return);
if ($include_footer)
{
$content .= parent::view('footer', $vars, $return);
}
return $content;
}
}