CakePHP Canonical HTML Helper Tag

How can I create this using html helper? (with inline = false, so I can specify it for each view)

<link rel="canonical" href="http://www.example.com/product.php?item=swedish-fish" />

Nothing seems to be found on this other than a patch that doesn't work.

+9
source share
4 answers

This was discovered on the BakeTracking CakePHP website: http://cakephp.lighthouseapp.com/projects/42648/tickets/1063-support-for-custom-meta-tag-elements-in-htmlhelper

Apparently you can use

echo $this->Html->meta('canonical', 'http:://example.com', array('rel'=>'canonical', 'type'=>null, 'title'=>null));
//outputs <link href="http:://example.com" rel="canonical" />
+9
source

It seems my friend just told me that I told him how to do this a few months ago, the problem is solved ...

<?php echo $this->Html->meta('canonical', 
    'http://www.example.com/product.php?item=swedish-fish', 
    array('rel'=>'canonical', 'type'=>null, 'title'=>null, 'inline' => false)
);?>
+8
source

-, url , $this->Html->url(null, true); $this->here; Cakephp html.

<?php echo $this->Html->meta('canonical', $this->Html->url(null, true), array('rel'=>'canonical', 'type'=>null, 'title'=>null)); ?>

<?php echo $this->Html->meta('canonical', $this->here, array('rel'=>'canonical', 'type'=>null, 'title'=>null)); ?>

: , $this->here .

+3
source

In CakePHP 2:

echo $this->Html->meta('canonical', 'http://example.com', array('rel' => 'canonical', 'type' => null, 'title' => null, 'inline' => false));

In CakePHP 3:

echo $this->Html->meta('canonical', 'http://example.com', array('rel' => 'canonical', 'type' => null, 'title' => null, 'block' => true));

Note that the main difference between the versions is what CakePHP 2 uses 'inline' => false, whereas CakePHP 3 uses 'block' => trueto place these tags in a tag <head>.

+1
source

All Articles