CakePHP Meta Tags

My scenario is this:

In my /views/layout/default.ctp

 <head> <!-- other stuff --> <?php echo $scripts_for_layout; ?> </head> <body> <!-- more stuff --> <?php echo $content_for_layout; ?> 

In my /views/pages/home.ctp

 <?php $this->Html->meta('keywords', 'my, keywords', array(), false); ?> 

However, my problem is that even with $scripts_for_layout in my default.ctp and with boolean inline = false I still don't see the meta tag in my head , instead I just see them inline.

I am reviewing a script in which it echoes $scripts_for_layout before I make this HTML helper call, but should there certainly be an elegant way to do this?

Also note that calling the HTML helper is the first line of my views/pages/home.ctp

Edit - Yeah, I found my mistake. Here is someone else who has the same problem. With CakePHP 1.3, the HTML helper syntax changes a bit (and there is no backward compatibility for the syntax).

Apparently, there is a syntactical flaw in what I wrote in my view . This is the correct way to say boolean inline = false in version 1.3:

 $this->Html->meta("keywords", "keywords, are, sweet", array("inline" => false)); 
+4
source share
2 answers

Yeah, I found my mistake. There seems to be a syntax flaw in what I wrote in my view . This is the correct way to say boolean inline = false in version 1.3:

 $this->Html->meta("keywords", "keywords, are, sweet", array("inline" => false)); 
+2
source

For CakePHP version 3.x, use this in your view:

 <?php $this->Html->meta('keywords', 'keywords, are, sweet', ['block' => true]); ?> 

Then in the layout header use:

 <?= $this->fetch('meta') ?> 

The output will be:

 <meta name="keywords" content="keywords, are, sweet"/> 
0
source

All Articles