7.4.1.3 meta

meta(string $type, string $url = null, array $attributes = array(), boolean $inline = true)

This method is handy for linking to external resources like RSS/Atom feeds and favicons. Like css(), you can specify whether or not you'd like this tag to appear inline or in the head tag using the fourth parameter.

If you set the "type" attribute using the $htmlAttributes parameter, CakePHP contains a few shortcuts:

type translated value
html text/html
rss application/rss+xml
atom application/atom+xml
icon image/x-icon
  <?php echo $html->meta(
    'favicon.ico',
    '/favicon.ico',
    array('type' => 'icon')
);?> //Output (line breaks added) </p>
<link
    href="http://example.com/favicon.ico"
    title="favicon.ico" type="image/x-icon"
    rel="alternate"
/>
 
<?php echo $html->meta(
    'Comments',
    '/comments/index.rss',
    array('type' => 'rss'));
?>
 
//Output (line breaks added)
<link
    href="http://example.com/comments/index.rss"
    title="Comments"
    type="application/rss+xml"
    rel="alternate"
/>
  1. <?php echo $html->meta(
  2. 'favicon.ico',
  3. '/favicon.ico',
  4. array('type' => 'icon')
  5. );?> //Output (line breaks added) </p>
  6. <link
  7. href="http://example.com/favicon.ico"
  8. title="favicon.ico" type="image/x-icon"
  9. rel="alternate"
  10. />
  11. <?php echo $html->meta(
  12. 'Comments',
  13. '/comments/index.rss',
  14. array('type' => 'rss'));
  15. ?>
  16. //Output (line breaks added)
  17. <link
  18. href="http://example.com/comments/index.rss"
  19. title="Comments"
  20. type="application/rss+xml"
  21. rel="alternate"
  22. />

This method can also be used to add the meta keywords and descriptions. Example:

<?php echo $html->meta(
    'keywords',
    'enter any meta keyword here'
);?>
//Output <meta name="keywords" content="enter any meta keyword here"/>
//

<?php echo $html->meta(
    'description',
    'enter any meta description here'
   );?> 

//Output <meta name="description" content="enter any meta description here"/>
  1. <?php echo $html->meta(
  2. 'keywords',
  3. 'enter any meta keyword here'
  4. );?>
  5. //Output <meta name="keywords" content="enter any meta keyword here"/>
  6. //
  7. <?php echo $html->meta(
  8. 'description',
  9. 'enter any meta description here'
  10. );?>
  11. //Output <meta name="description" content="enter any meta description here"/>

If you want to add a custom meta tag then the first parameter should be set to an array. To output a robots noindex tag use the following code:

 echo $html->meta(array('name' => 'robots', 'content' => 'noindex')); 
  1. echo $html->meta(array('name' => 'robots', 'content' => 'noindex'));