Opencart 2.2:如何将扩展名称传递到featured模板视图
Since you’ve set up multiple instances of the Featured module, each can display its own unique name that you configured in the admin. Here’s how to pass that custom name to your template instead of using the fixed "featured" text from the language file:
Step 1: Modify the Featured Controller
Open catalog/controller/module/featured.php and find the line where $data['heading_title'] is assigned. By default, it looks like this:
$data['heading_title'] = $this->language->get('heading_title');
Replace that line with this code, which pulls the custom name from your module instance settings:
// Ensure we have the correct module instance settings $module_id = isset($this->request->get['module_id']) ? $this->request->get['module_id'] : 0; $setting = $this->config->get('featured_module_' . $module_id); // Use custom module name if set, else fall back to default language text if (!empty($setting['name'])) { $data['heading_title'] = $setting['name']; } else { $data['heading_title'] = $this->language->get('heading_title'); }
(Note: If $setting is already defined earlier in the controller, you can skip re-declaring it—just keep the conditional check for $setting['name'].)
Step 2: Set Custom Names for Your Module Instances
- Log into your OpenCart Admin panel
- Go to Extensions > Modules
- Edit each of your 4 Featured module instances
- Enter a unique name in the Module Name field (e.g., "Featured Electronics", "Top Selling Apparel")
- Save the module settings
Step 3: Clear Cache
For the changes to take effect right away:
- Navigate to System > Maintenance > Cache
- Click the Clear button to purge the cache
How It Works
Each module instance’s settings (including your custom name) are stored in the database under a key like featured_module_X (where X is the module ID). The modified controller retrieves this custom name and passes it to the featured.tpl template, which already uses $heading_title to display the section title.
Now each Featured block on your homepage will show the unique name you assigned to its module instance instead of the generic "Featured" text.
内容的提问来源于stack exchange,提问作者Mudassar Khani

