Post by theme » Mon Aug 08, 2016 3:01 pm

I want applied template name in header.tpl , using opencart version 2.3.0.2

I have tried below code

Code: Select all

<link rel="stylesheet" type="text/css" href="catalog/view/theme/<?php echo $config->get('theme_default_directory') ?>/stylesheet/example.css" media="all">
Error:
<b>Fatal error</b>: Call to a member function get() on a non-object in <b>/var/www/html/veritodemo1/catalog/view/theme/veritodemo1/template/common/header.tpl</b> on line <b>30</b><br />

Newbie

Posts

Joined
Thu Mar 10, 2016 5:23 pm

Post by opencartboost » Mon Aug 08, 2016 5:25 pm

Do you try it for OC 2.3.0.2 only or other 2.x too?
As i know, for oc 2.x not allowed to echo $config->get in file view.

You must define variable in file controller first.
Try in file controller like this :

Code: Select all

$data['theme_default_directory'] = $this->config->get('theme_default_directory');
and echo in file view

Code: Select all

<?php echo $theme_default_directory; ?>

Active Member

Posts

Joined
Thu Jul 09, 2015 5:59 am

Post by theme » Mon Aug 08, 2016 7:06 pm

For opencart version 2.2.0.0

Code: Select all

<?php echo $config->get('theme_default_directory'); ?>
works perfectly fine in view file.
Last edited by straightlight on Mon Aug 08, 2016 7:18 pm, edited 2 times in total.
Reason: Added code tags.

Newbie

Posts

Joined
Thu Mar 10, 2016 5:23 pm

Post by straightlight » Mon Aug 08, 2016 7:21 pm

As i know, for oc 2.x not allowed to echo $config->get in file view.
That would be incorrect. It is still feasible to add the globalization but highly non-suggested. Below is a topic that explains this theory.
theme wrote:works perfectly fine in view file.
It may work fine but is not a suggested approach I would use. Followed is an identical subject request which explains in details what happens when forum users uses the globalization function: http://forum.opencart.com/viewtopic.php ... on#p632488 .
The provided codes I specified on the above should work as intended. Although, I do NOT recommend nor suggest to add any globalization functions into the themes as it skips each registered objects being passed through the Object Registry of Opencart.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / 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 9 guests