【发布时间】:2019-07-01 03:26:40
【问题描述】:
我想在 common/header twig 文件中添加一个变量/显示,可以通过新的扩展进行管理。新扩展已创建。启动模块
我添加了: admin/view/template/extension/module/starter_module.twig
<div class="form-group">
<label class="col-sm-2 control-label" for="input-new">New</label>
<div class="col-sm-10">
<select name="new" id="input-new" class="form-control">
{% if new %}
<option value="1" selected="selected">Enabled</option>
<option value="0">Disabled</option>
{% else %}
<option value="1">Enabled</option>
<option value="0" selected="selected">Disabled</option>
{% endif %}
</select>
</div>
</div>
在 admin/controller/extension/module/starter_module.php 中
if (isset($this->request->post['new'])) {
$data['new'] = $this->request->post['new'];
} elseif (!empty($module_info)) {
$data['new'] = $module_info['new'];
} else {
$data['new'] = '';
}
在目录/控制器/扩展/模块/starter_module.php中
$data['new'] = $this->config->get('new');
$data['new'] = (int) $setting['new'];
在目录/视图/主题/默认/模板/common/header.twig中
{% if new %}Enabled {% else %} disabled{% endif %}
但我总是只得到禁用的结果,缺少什么?不能将变量从扩展发送到公共标头?
如果您知道问题,请帮助我,非工作文件在这里https://github.com/bblori/Opencart3
您可以在这里看到我在设置/设置文件中设置的工作变量之一并且正在工作。
https://github.com/bblori/Enable-Style-OC3
XML 代码
<modification>
<name>Starter Module</name>
<code>starter-module</code>
<version>1.0.0</version>
<author>Author</author>
<link>http://domain/</link>
<file path="catalog/controller/common/header.php">
<operation>
<search><![CDATA[return $this->load->view('common/header', $data);]]></search>
<add position="before"><![CDATA[
$data['config_new'] = $this->config->get('config_new');
]]></add>
</operation>
</file>
非常感谢
【问题讨论】:
-
解决方案:我在 vqmod 中创建了一个 xml 文件,在其中添加了要插入到控制器/标题中的代码。
标签: opencart opencart-3