Page 1 of 1
Adding css override file in admin for second language
Posted: Sun Jul 24, 2016 6:34 pm
by fantastico
Hello
In opencart v2.2.0.0 with 2 admin languages, i would like to add a new css file with few override css changes that will affect only one language.
I tried with the following code in header.tpl:
Code: Select all
<?php if ($this->config->get('config_language') == 'es-es') { ?>
<link rel="stylesheet" type="text/css" href="catalog/view/theme/default/stylesheet/es.css" />
<?php } ?
but got an error:
Notice: Undefined property: Template\Basic::$config in /home/xxx/public_html/new/admin/view/template/common/header.tpl on line 24
Fatal error: Call to a member function get() on a non-object in /home/xxx/public_html/new/admin/view/template/common/header.tpl on line 24
Thanks for your help.
Re: Adding css override file in admin for second language
Posted: Sun Jul 24, 2016 7:42 pm
by straightlight
A more simplistic approach would be with VQMod. The correct statement you'd be looking for without altering core files would be by calling this method from the admin/controller/common/header.php file,
e.g you could use:
Code: Select all
if ($this->config->get('config_admin_language') == 'es-es') {
$this->document->addScript('view/stylesheet/es.css');
}
by adding es.css, first, into that folder. The CSS will be added to the <head> content of the header.tpl according when the case.

Re: Adding css override file in admin for second language
Posted: Mon Jul 25, 2016 1:43 am
by fantastico
Thanks for your reply straightlight.
I am struggling with this code and could not make it work, the css file does not load. This is what i got for the vqmod file so far:
Code: Select all
<modification>
<id>Add CSS</id>
<version>0.1</version>
<vqmver>2.6.1</vqmver>
<author>Me</author>
<file name="admin/controller/common/header.php">
<operation>
<search position="before"><![CDATA[
$data['description'] = $this->document->getDescription();
]]>
</search>
<add><![CDATA[
if ($this->config->get('config_admin_language') == 'es-es') {
$this->document->addScript('view/stylesheet/es.css');
}
]]>
</add>
</operation>
</file>
</modification>
Maybe the position is wrong?
Thanks, appreciate your reply.
Re: Adding css override file in admin for second language
Posted: Mon Jul 25, 2016 1:53 am
by straightlight
fantastico wrote:Thanks for your reply straightlight.
I am struggling with this code and could not make it work, the css file does not load. This is what i got for the vqmod file so far:
Code: Select all
<modification>
<id>Add CSS</id>
<version>0.1</version>
<vqmver>2.6.1</vqmver>
<author>Me</author>
<file name="admin/controller/common/header.php">
<operation>
<search position="before"><![CDATA[
$data['description'] = $this->document->getDescription();
]]>
</search>
<add><![CDATA[
if ($this->config->get('config_admin_language') == 'es-es') {
$this->document->addScript('view/stylesheet/es.css');
}
]]>
</add>
</operation>
</file>
</modification>
Maybe the position is wrong?
Thanks, appreciate your reply.
Is your current selected language 'es-es' on the admin-end? When viewing the source from your browser, look for: 'es.css' file (without quotes). Did you also uploaded the es.css file into your admin/view/stylesheet folder?
Re: Adding css override file in admin for second language
Posted: Mon Jul 25, 2016 2:22 am
by fantastico
Ok, thanks for the tip.
In view source i can see the loaded css file, but it loads wrong values:
Code: Select all
<script type="text/javascript" src="view/stylesheet/es.css"></script>
instead of:
<link type="text/css" href="view/stylesheet/es.css" rel="stylesheet" media="screen" />
How can i fix it?
Re: Adding css override file in admin for second language
Posted: Mon Jul 25, 2016 3:00 am
by straightlight
fantastico wrote:Ok, thanks for the tip.
In view source i can see the loaded css file, but it loads wrong values:
Code: Select all
<script type="text/javascript" src="view/stylesheet/es.css"></script>
instead of:
<link type="text/css" href="view/stylesheet/es.css" rel="stylesheet" media="screen" />
How can i fix it?
This portion does not make sense since text/javascript cannot import CSS files.
However, change to:
Code: Select all
if ($this->config->get('config_admin_language') == 'es-es') {
$this->document->addStyle('view/stylesheet/es.css');
}
This should resolved the problem.
Re: Adding css override file in admin for second language
Posted: Mon Jul 25, 2016 4:14 am
by fantastico
Thank you so much straightlight, that fixed it.
Great support!
Re: Adding css override file in admin for second language
Posted: Mon Jul 25, 2016 5:17 am
by straightlight
fantastico wrote:Thank you so much straightlight, that fixed it.
Great support!
No problem, enjoy.