简体   繁体   中英

Override CakePHP head/header

EDIT: I found the solution, but now there is a problem with cakePhp itself

I am using:

<?php if (isset($image)) echo $this->Html->meta(array('name' => 'og:image', 'content' => $image)); ?>

and it generates

<meta name="og:image" content="https://test.com/img/sharer/startseite.jpg"/>

Sadly Facebook doesn´t like the /> at the end (related here Facebook Open Graph Error - Inferred Property )

I have to use it with a space - but CakePhp generates it that way. Any ideas?

In CakePHP 3, you can find templates for the HTML helper in vendor/cakephp/cakephp/src/View/Helper/HtmlHelper.php .

Copy those to config/templates/html-templates.php and enhance them according to your demands.

Then, in your \\App\\Controller\\AppController , add

public $helpers = [
  ...
  'Html' => ['templates' => 'templates/html-templates'],
];

and use your HTML helper as usual.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM