0

For example in Wordpress you can call to home with:

<?php echo home_url(); ?>

But in OpenCart I can't find a similar function. In my header this works:

<?php echo $base; ?>

But not on other templates in my theme. Someone who got a global function for this in OpenCart? Or a library to share, would be perfect!

I work with OpenCart 2.0

Henric Åkesson
  • 140
  • 1
  • 2
  • 11

5 Answers5

1

Try this,

<?php echo HTTP_SERVER; ?>
Matricore
  • 575
  • 7
  • 12
0

In the controller of the page, in my case footer.php I pasted this:

if ($this->request->server['HTTPS']) {
$server = $this->config->get('config_ssl');
} else {
$server = $this->config->get('config_url');
}

$data['base'] = $server;

And then in my template, footer.tpl I could use:

<?php echo $base; ?>
Henric Åkesson
  • 140
  • 1
  • 2
  • 11
  • This is not going to respect your SEO urls. If you just wanted to link to `http://yoursite.com/` why not just use `/`? – rjdown Oct 29 '14 at 17:59
0

The correct way to do this in OpenCart is to use

<?php echo $this->url->link('common/home'); ?>

Note that this adds the full URL and route, not just / which is not possible using the SEO URL class without modification

Jay Gilford
  • 15,141
  • 5
  • 37
  • 56
  • Ah missed the 2.0 reference. You'll need to either set the variable in the controller, or use a pretty hackish method of `link('common/home'); ?>` in your template (not recommended) – Jay Gilford Oct 30 '14 at 21:37
0
<?php echo $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'); ?>
Gavin Simpson
  • 2,766
  • 3
  • 30
  • 39
  • How so Mr SVMRAJESH? "Someone who got a global function for this in OpenCart?". – Gavin Simpson Oct 30 '14 at 06:57
  • @SVMRAJESH You should learn a lot about SO and reviewing. It is not enough to just see a *short answer*, *one line of code* to flag it - read also the question, switch on your brain and think... – shadyyx Oct 30 '14 at 08:05
  • Gavin I posted similar code until I realised this was OC2. It no longer works directly inside templates :( – rjdown Oct 30 '14 at 17:38
  • @rjdown, I am currently working on OC2, and this is straight from one of the existing modules. I am using link just like it in my own custom template/module, and it works just fine. Perhaps I am missing something? – Gavin Simpson Nov 01 '14 at 13:58
0

Copy from controller/common/home/header.php

$this->load->language('common/header');
$data['text_home'] = $this->language->get('text_home');

and

$data['home'] = $this->url->link('common/home');

Add these to whichever controller needs them Copy from header.tpl

href="<?php echo $home; ?>"

add to whichever template needs it.

Would that not cover SEO and link needs?