在OpenCart 3中添加新模块位置 [英] Adding new modules positions to OpenCart 3
问题描述
我正在使用 OpenCart版本3.0.2 .
默认情况下,OpenCart有4个区域,我们可以在其中放置模块.即
By default OpenCart has 4 areas where we can drop the modules in our layouts. i.e.
- 左列
- 右列
- 热门内容
- 底部内容
我的问题是,是否可以以某种方式将模块拖放到其他位置,或者是否可以以某种方式在HTML-Module中调用模块并包装一些HTML代码.基本上,我的设计是固定的,我想在主页上添加一些动态横幅,但是要根据设计显示它们,它们通常包裹在行中,而不是col-6,因为bootstrap是我正在使用的框架.
My question is if somehow we can drop modules elsewhere also or maybe if we can somehow call a module within the HTML-Module and wrap is with some HTML codes. Basically I am stuck with a design where I wanted to add few dynamic banners in the home page but to display them according to the design, they much be wrapped within row and than col-6 each since bootstrap is the framework I am using.
要详细说明我的要求,我正在编写示例HTML,以便可以显示要为主页添加模块的位置
To elaborate my requirement I am writing sample HTML so that I can show where I wanted to add modules for the home page
<header></header>
<div id="home" class="row">
<div class="col-12"> Slideshow Module as "content top" </div>
<div class="col-6"> Big Banner Module </div>
<div class="col-6"> Few more Banners </div>
<div class="col-12"> Latest Products Module as "content Bottom" </div>
<div class="col-12"> Featured Products Module as "content Bottom" </div>
<div class="col-12"> HTML CONTENT Module as "content Bottom" </div>
</div>
<footer></footer>
有可能我可以在左右列中放置 Big Banner Module和更多的Banners模块,并使用一些jQuery将列的环绕HTML从<aside id="column-left">
更改为<div class="col-6">
,但是这种解决方案似乎不合适,并且也会影响Google的抓取.
There is a possibility that I can drop Big Banner Module and a few more Banners modules in left and right columns and a bit of jQuery to change the wrapping HTML of the columns from <aside id="column-left">
to <div class="col-6">
but this solution do not seems right and will effect the google crawling as well.
有人会建议只为主页添加这样的模块的更好方法吗?
Would someone suggest a better way to add modules like this only for the home page?
如果无法解释HTML的问题,则为结构图:
A structure image in case if I am unable to explain the problem with HTML:
推荐答案
您需要创建新职位.
文件:
admin/language/en-gb/design/layout.php
查找:
$_['text_content_bottom']
在其之前添加:
$_['text_content_new'] = 'Content New';
文件:
admin/view/template/design/layout_form.twig
查找:
<table id="module-content-top" class="table table-striped table-bordered table-hover">
在其之前添加:
<table id="module-content-new" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<td class="text-center">{{ text_content_new }}</td>
</tr>
</thead>
<tbody>
{% for layout_module in layout_modules %}
{% if layout_module.position == 'content_new' %}
<tr id="module-row{{ module_row }}">
<td class="text-left"><div class="input-group">
<select name="layout_module[{{ module_row }}][code]" class="form-control input-sm">
{% for extension in extensions %}
<optgroup label="{{ extension.name }}">
{% if not extension.module %}
{% if extension.code == layout_module.code %}
<option value="{{ extension.code }}" selected="selected">{{ extension.name }}</option>
{% else %}
<option value="{{ extension.code }}">{{ extension.name }}</option>
{% endif %}
{% else %}
{% for module in extension.module %}
{% if module.code == layout_module.code %}
<option value="{{ module.code }}" selected="selected">{{ module.name }}</option>
{% else %}
<option value="{{ module.code }}">{{ module.name }}</option>
{% endif %}
{% endfor %}
{% endif %}
</optgroup>
{% endfor %}
</select>
<input type="hidden" name="layout_module[{{ module_row }}][position]" value="{{ layout_module.position }}" />
<input type="hidden" name="layout_module[{{ module_row }}][sort_order]" value="{{ layout_module.sort_order }}" />
<div class="input-group-btn"> <a href="{{ layout_module.edit }}" type="button" data-toggle="tooltip" title="{{ button_edit }}" target="_blank" class="btn btn-primary btn-sm"><i class="fa fa-pencil"></i></a>
<button type="button" onclick="$('#module-row{{ module_row }}').remove();" data-toggle="tooltip" title="{{ button_remove }}" class="btn btn-danger btn-sm"><i class="fa fa fa-minus-circle"></i></button>
</div>
</div></td>
</tr>
{% set module_row = module_row + 1 %}
{% endif %}
{% endfor %}
</tbody>
<tfoot>
<tr>
<td class="text-left"><div class="input-group">
<select class="form-control input-sm">
<option value=""></option>
{% for extension in extensions %}
<optgroup label="{{ extension.name }}">
{% if not extension.module %}
<option value="{{ extension.code }}">{{ extension.name }}</option>
{% else %}
{% for module in extension.module %}
<option value="{{ module.code }}">{{ module.name }}</option>
{% endfor %}
{% endif %}
</optgroup>
{% endfor %}
</select>
<div class="input-group-btn">
<button type="button" onclick="addModule('content-new');" data-toggle="tooltip" title="{{ button_module_add }}" class="btn btn-primary btn-sm"><i class="fa fa-plus-circle"></i></button>
</div>
</div></td>
</tr>
</tfoot>
</table>
创建以下文件:
catalog/controller/common/content_new.php
内容:
<?php
class ControllerCommonContentNew extends Controller {
public function index() {
$this->load->model('design/layout');
if (isset($this->request->get['route'])) {
$route = (string)$this->request->get['route'];
} else {
$route = 'common/home';
}
$layout_id = 0;
if ($route == 'product/category' && isset($this->request->get['path'])) {
$this->load->model('catalog/category');
$path = explode('_', (string)$this->request->get['path']);
$layout_id = $this->model_catalog_category->getCategoryLayoutId(end($path));
}
if ($route == 'product/product' && isset($this->request->get['product_id'])) {
$this->load->model('catalog/product');
$layout_id = $this->model_catalog_product->getProductLayoutId($this->request->get['product_id']);
}
if ($route == 'information/information' && isset($this->request->get['information_id'])) {
$this->load->model('catalog/information');
$layout_id = $this->model_catalog_information->getInformationLayoutId($this->request->get['information_id']);
}
if (!$layout_id) {
$layout_id = $this->model_design_layout->getLayout($route);
}
if (!$layout_id) {
$layout_id = $this->config->get('config_layout_id');
}
$this->load->model('setting/module');
$data['modules'] = array();
$modules = $this->model_design_layout->getLayoutModules($layout_id, 'content_new');
foreach ($modules as $module) {
$part = explode('.', $module['code']);
if (isset($part[0]) && $this->config->get('module_' . $part[0] . '_status')) {
$module_data = $this->load->controller('extension/module/' . $part[0]);
if ($module_data) {
$data['modules'][] = $module_data;
}
}
if (isset($part[1])) {
$setting_info = $this->model_setting_module->getModule($part[1]);
if ($setting_info && $setting_info['status']) {
$output = $this->load->controller('extension/module/' . $part[0], $setting_info);
if ($output) {
$data['modules'][] = $output;
}
}
}
}
return $this->load->view('common/content_new', $data);
}
}
创建以下文件:
catalog/view/theme/default/template/common/content_new.twig
内容:
{% for module in modules %}
{{ module }}
{% endfor %}
文件:
catalog/controller/common/home.php
查找:
$data['content_top'] = $this->load->controller('common/content_top');
在其之前添加:
$data['content_new'] = $this->load->controller('common/content_new');
文件:
catalog/view/theme/default/template/common/home.twig
查找:
{{ header }}
在其后添加:
{{ content_new }}
这篇关于在OpenCart 3中添加新模块位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!