Thursday, January 16, 2014
How to handle the meta title,description/keywords in a Zend Framework 2 application?
To inject Title, Meta Keywords, Meta Description
Layput file code -
layout.phtml
<html>
<head>
<?php echo $this->headTitle(); ?>
<!-- Display Meta Keywords and Description along with Viewport -->
<?php echo $this->headMeta()->appendName('viewport', 'width=device-width, initial-scale=1.0') ?>
<meta charset="utf-8">
</head>
<body>
...
</body>
</html>
Do following code in the Controller like this:
public function indexAction()
{
$renderer = $this->getServiceLocator()->get('Zend\View\Renderer\PhpRenderer');
$renderer->headTitle('Head Title');
$renderer->headMeta()->appendName('keywords', 'Meta Keywords');
$renderer->headMeta()->appendName('description', 'Meta Description');
return new ViewModel();
}
Layput file code -
layout.phtml
<html>
<head>
<?php echo $this->headTitle(); ?>
<!-- Display Meta Keywords and Description along with Viewport -->
<?php echo $this->headMeta()->appendName('viewport', 'width=device-width, initial-scale=1.0') ?>
<meta charset="utf-8">
</head>
<body>
...
</body>
</html>
Do following code in the Controller like this:
public function indexAction()
{
$renderer = $this->getServiceLocator()->get('Zend\View\Renderer\PhpRenderer');
$renderer->headTitle('Head Title');
$renderer->headMeta()->appendName('keywords', 'Meta Keywords');
$renderer->headMeta()->appendName('description', 'Meta Description');
return new ViewModel();
}
Subscribe to:
Comments (Atom)