Post by fantastico » Sun Jul 24, 2016 6:34 pm

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.
Last edited by straightlight on Sun Jul 24, 2016 7:30 pm, edited 1 time in total.
Reason: Quote and code tags added.

New member

Posts

Joined
Wed Feb 20, 2013 2:47 am

Post by straightlight » Sun Jul 24, 2016 7:42 pm

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. :)

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by fantastico » Mon Jul 25, 2016 1:43 am

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.

New member

Posts

Joined
Wed Feb 20, 2013 2:47 am

Post by straightlight » Mon Jul 25, 2016 1:53 am

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?

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by fantastico » Mon Jul 25, 2016 2:22 am

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?
Last edited by straightlight on Mon Jul 25, 2016 2:59 am, edited 1 time in total.
Reason: Added code tags.

New member

Posts

Joined
Wed Feb 20, 2013 2:47 am

Post by straightlight » Mon Jul 25, 2016 3:00 am

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.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by fantastico » Mon Jul 25, 2016 4:14 am

Thank you so much straightlight, that fixed it.
Great support!

New member

Posts

Joined
Wed Feb 20, 2013 2:47 am

Post by straightlight » Mon Jul 25, 2016 5:17 am

fantastico wrote:Thank you so much straightlight, that fixed it.
Great support!
No problem, enjoy.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 6 guests