I am trying to make two global variables within OpenCart. I basically want to be able to declare them in any of my .tpl
files
<?php echo $global1; ?>
I have tried editing, library/system.php
and also config.php
by adding $global1="test"
inside my files. However calling that in .tpl
files is not working?
Example, look at the file below, I want to be able to call these variables anytime.. do I have to edit config.php or what?? The example shows the $header
call which is used on every .tpl file.
not_found.tpl
<?=$header?>
<div class="breadcrumb">
<? foreach ($breadcrumbs as $breadcrumb) { ?>
<? $breadcrumb['separator']; ?><a href="<?=$breadcrumb['href']?>"><?=$breadcrumb['text']?></a>
<? } ?>
</div>
<div id="content">
<?=$global1?>
<img src="/catalog/view/theme/default/image/error.png"/>
</div>
<?=$footer?>
Updated
/catalog/controller/common/header.php
<?php
class ControllerCommonHeader extends Controller {
protected function index() {
// NEW GLOBAL VARS
$cdnDefault="//www.gorgeouscouturedev.com/catalog/view/theme/";
$currentUseLang = $this->language->get('code');
And now in /catalog/view/theme/default/template/common/home.tpl
<?=$header?>
<?=$column_left?>
<?=$column_right?>
<div id="content">
<? echo $cdnDefault ?>
<? echo $currentUseLang ?>
<?=$content_top?>
<div class="flexslider">
<ul class="slides">
<li><img src="catalog/view/theme/default/image/desktop.png"/></li>
<li><img src="catalog/view/theme/default/image/blogger.png"/></li>
</ul>
</div>
<?=$content_bottom?>
</div>
<?=$footer?>
And the errors:
Notice: Undefined variable: cdnDefault in /catalog/view/theme/default/template/common/home.tpl on line 6
Notice: Undefined variable: currentUseLang in /catalog/view/theme/default/template/common/home.tpl on line 7