Check module position in OpenCart 2.0

I used the following code to check the position of the module. So, it works great in OpenCart 1.5.6. When the module is enabled in the left and right content pane, so I want to hide JavaScript code in OpenCart

but it does not work in opencart 2.0

How can one achieve it in Opencart 2.0?

in the .tpl file

<?php if ($module['position'] == 'content_bottom' || $module['position'] == 'content_top') { ?> //add your code Here <?php } ?> 

add .php file

 $this->data['module'] = $setting; 
+5
source share
2 answers

I found a simple solution. It works like a charm.

Step 1

in the .tpl file. (You want this module. Featured.tpl, etc.)

 <?php if ($module['position'] == 'content_bottom' || $module['position'] == 'content_top') { ?> //add your code Here <?php } ?> 

Step 2

add to the .php file (you want this module. featured.php, etc.)

 $data['module'] = $setting; 


Step 3 (if you are using OpenCart version 2.0.0.0)

directory / controller / shared / { content_top, content_bottom, content_right, content_left }. php

Find the code below

 if (isset($part[1]) && isset($setting[$part[1]])) { 

and add below code after

 $setting[$part[1]]['position'] = basename(__FILE__, '.php'); 


Step 3 (if you are using OpenCart version 2.0.1.x.)

directory / controller / shared / { content_top, content_bottom, content_right, content_left }. php

Find the code below

 $setting_info = $this->model_extension_module->getModule($part[1]); 

and add below code after

 $setting_info['position'] = basename(__FILE__, '.php'); 
+1
source

OC 2.0 is a major upgrade, so many things that work with OC 1.5.X may not work in OC 2.X

For example, we used OC 1.5.x to add the layout to the module in OC 2.0, we add the modules to the So In 1.5.x layout, we used to search for the Module and its associated positions. Now we find the Positions and related modules.

Suppose you are working on \catalog\controller\common\content_top.php

After

$modules = $this->model_design_layout->getLayoutModules($layout_id, 'content_top');

Selects all modules installed on the content_top particular layout.

Add

 $search_text = 'featured'; // name of the module you want to find $matched_top = array_filter($modules, function($el) use ($search_text) { return ( strpos($el['code'], $search_text) !== false ); }); if(!empty($matched_top)){ $data['truevalue'] = 1; } 

Now in content_top.tpl you can write a script

 if(isset($truevalue)){ //here goes script code } 

Similarly, you can do the same for content_bottom

0
source

Source: https://habr.com/ru/post/1209647/


All Articles