Henric Åkesson
Henric Åkesson

Reputation: 150

Dynamic home link for OpenCart

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

Upvotes: 0

Views: 1555

Answers (5)

Billy Boyle
Billy Boyle

Reputation: 19

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?

Upvotes: 0

Matricore
Matricore

Reputation: 593

Try this,

<?php echo HTTP_SERVER; ?>

Upvotes: 1

Gavin Simpson
Gavin Simpson

Reputation: 2822

<?php echo $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'); ?>

Upvotes: 0

Jay Gilford
Jay Gilford

Reputation: 15151

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

Upvotes: 0

Henric &#197;kesson
Henric &#197;kesson

Reputation: 150

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; ?>

Upvotes: 0

Related Questions