Post by guldan » Sat Apr 06, 2013 5:20 pm

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.
Last edited by guldan on Fri Apr 19, 2013 2:18 pm, edited 1 time in total.

Newbie

Posts

Joined
Sat Apr 06, 2013 5:06 pm

Post by guldan » Mon Apr 08, 2013 11:59 am

Hello, can anybody please help me...? :)

Newbie

Posts

Joined
Sat Apr 06, 2013 5:06 pm

Post by guldan » Tue Apr 16, 2013 12:37 pm

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...

Newbie

Posts

Joined
Sat Apr 06, 2013 5:06 pm

Post by MarketInSG » Thu Apr 18, 2013 3:45 pm

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


User avatar
Guru Member

Posts

Joined
Wed Nov 16, 2011 11:53 am
Location - Singapore

Post by felixjsc » Thu Apr 18, 2013 5:06 pm

Yes, it is right! ;D

Newbie

Posts

Joined
Fri Jan 13, 2012 4:57 pm
Location - New York

Post by guldan » Thu Apr 18, 2013 10:44 pm

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!!

Newbie

Posts

Joined
Sat Apr 06, 2013 5:06 pm

Post by MarketInSG » Fri Apr 19, 2013 9:28 am

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


User avatar
Guru Member

Posts

Joined
Wed Nov 16, 2011 11:53 am
Location - Singapore

Post by guldan » Fri Apr 19, 2013 12:11 pm

Done! I implemented it via vqmod and it works perfectly.
Many thanks MarketInSG!

Newbie

Posts

Joined
Sat Apr 06, 2013 5:06 pm

Post by guldan » Fri Apr 19, 2013 12:17 pm

By the way, how to mark this topic as SOLVED?
How to edit the topic title? :)
Thanks.

Newbie

Posts

Joined
Sat Apr 06, 2013 5:06 pm

Post by MarketInSG » Fri Apr 19, 2013 12:52 pm

edit the first post you made and add a solved if i'm not wrong. Can't really remember


User avatar
Guru Member

Posts

Joined
Wed Nov 16, 2011 11:53 am
Location - Singapore
Who is online

Users browsing this forum: No registered users and 44 guests