You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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:

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

  1. Log into your OpenCart Admin panel
  2. Go to Extensions > Modules
  3. Edit each of your 4 Featured module instances
  4. Enter a unique name in the Module Name field (e.g., "Featured Electronics", "Top Selling Apparel")
  5. Save the module settings

Step 3: Clear Cache

For the changes to take effect right away:

  1. Navigate to System > Maintenance > Cache
  2. 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 03:42:51