如何在Zend框架布局中更改元标记 [英] How to change meta tags in zend framework layout
问题描述
所以我在
$this->headTitle() and $this->headMeta()->appendName()
并在layout.phtml的标题
and is echoed at layout.phtml's header
我的问题是:如何更改视图文件中的那些默认元标记,以使它们被替换?
My question is: How do I change those default meta tags from the view file such that they are replaced?
我尝试使用:
$this->headMeta()->appendName() or setName()
与其替换旧的默认元标记,不如创建一个全新的元标记.我该如何更换它们?
Instead of replacing the old default meta tags, it would create an entirely new meta tag. How can I replace them?
推荐答案
我建议为关键字设置一个视图变量. 例如,在您的 bootstrap.php 中,您可以如下定义默认关键字:
I would recommend setting a view variable for the keywords. For example, in your bootstrap.php you could define a default keywords as follows:
protected function _initSetDefaultKeywords() {
$view = $this->bootstrap('view')->getResource('view');
$view->keywords = 'default keywords';
}
然后在 layout.phtml 中,您将:
<?php echo $this->headMeta()->appendName('keywords', $this->keywords); ?>
最后,在您的视图(或操作)中,您只需更改关键字view变量即可更改元关键字:
Finally, in your views (or actions) you could change the meta keywords simply by changing the keywords view variable:
// in an action
$this->view->keywords = 'new kewords';
//or in a view
<?php $this->keywords = 'new kewords'; ?>
这篇关于如何在Zend框架布局中更改元标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!