Page 1 of 1
[SOLVED] How to echo canonical link in product.tpl?
Posted: Sat Apr 06, 2013 5:20 pm
by guldan
Hello all, I'm new in this forum. Here is my question:
I'm using Opencart 1.5.4.
How to echo canonical link in the product.tpl? I need that for some reason (twitter counturl).
I can see in the header.tpl that canonical link is easily echoed using this:
Code: Select all
<link href="<?php echo $link['href']; ?>" rel="<?php echo $link['rel']; ?>" />
But when I tried to echo $link['href'] in the product.tpl, it echoes nothing.
I think this must be something related with controller file.
But I just want simple solution. Since the canonical link has been declared in the header, can we just "copy paste" that form header.tpl to product.tpl?
Example, in header.tpl we use $copy_canonical = $link['href']; and then in product.tpl just echo $copy_canonical;
I think that will not be as simple as that, right?
What is the simplest solution?
Thank you.
Re: How to echo canonical link in product.tpl?
Posted: Mon Apr 08, 2013 11:59 am
by guldan
Hello, can anybody please help me...?

Re: How to echo canonical link in product.tpl?
Posted: Tue Apr 16, 2013 12:37 pm
by guldan
Nobody? Wow, I can believe it. It must be a simple question for a lot of opencart Masters here.
Since I don't know how a variable is passed between file in MVC like opencart, i don't know the procedure.
But the logic itself should be easy, right?
Anybody, pleaseee...
Re: How to echo canonical link in product.tpl?
Posted: Thu Apr 18, 2013 3:45 pm
by MarketInSG
find
Code: Select all
$this->document->addLink($this->url->link('product/product', 'product_id=' . $this->request->get['product_id']), 'canonical');
and below add
Code: Select all
$this->data['canonical_url'] = $this->url->link('product/product', 'product_id=' . $this->request->get['product_id']);
then go to product.tpl and echo $cannoical_url
Re: How to echo canonical link in product.tpl?
Posted: Thu Apr 18, 2013 5:06 pm
by felixjsc
Yes, it is right!

Re: How to echo canonical link in product.tpl?
Posted: Thu Apr 18, 2013 10:44 pm
by guldan
Hi MarketInSG, thanks a lot for your answer. Finally...

In your reply above, you asked me to find a line of code and then add another line below it.
But in which file? You don't mention it
What I'm trying now is just directly echo your code in the product.tpl like this
Code: Select all
echo $this->data['canonical_url'] = $this->url->link('product/product', 'product_id=' . $this->request->get['product_id']);
and it works!!
Is it a right procedure to echo it directly in product.tpl? Not in some controller file?
It works already as what I want (and I'm so happy), but I'm afraid if there is side effect when we echo it directly in the product.tpl.
Thankkks!!
Re: How to echo canonical link in product.tpl?
Posted: Fri Apr 19, 2013 9:28 am
by MarketInSG
there's no side effect to do it in product.tpl. You can do that if you're lazy
Code: Select all
echo $this->url->link('product/product', 'product_id=' . $this->request->get['product_id']);
Else, you can follow my instructions above and add into controller/product.php
Re: How to echo canonical link in product.tpl?
Posted: Fri Apr 19, 2013 12:11 pm
by guldan
Done! I implemented it via vqmod and it works perfectly.
Many thanks MarketInSG!
Re: How to echo canonical link in product.tpl?
Posted: Fri Apr 19, 2013 12:17 pm
by guldan
By the way, how to mark this topic as SOLVED?
How to edit the topic title?

Thanks.
[SOLVED] Re: How to echo canonical link in product.tpl?
Posted: Fri Apr 19, 2013 12:52 pm
by MarketInSG
edit the first post you made and add a solved if i'm not wrong. Can't really remember