Zend:如何在我的所有视图中添加网页标题?
现在,我必须在所有视图中分别添加标题,如下所示:
<head>
<title>TestProject - Home</title>
</head>
现在
<head>
<title>TestProject - Dashboard</title>
</head>
,如果我想更改标题的 TestProject 部分,那么我必须在所有视图中更改它。我如何在 BootStrap.php 中提及这一点并将其添加到所有视图中?每当我必须改变这一点时,我都会在一个地方改变它。
For now I have to add title in all my views separately like this:
<head>
<title>TestProject - Home</title>
</head>
and
<head>
<title>TestProject - Dashboard</title>
</head>
Now if I want to change TestProject part of title then I have to change it in all my views. How can I mentioned this in BootStrap.php and add it in all views? And whenever I have to change this, I will change this in one place.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您应该查看
headTitle
视图助手。您可以将此代码片段放在引导文件下面(来自 http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.headtitle)。然后,您可以在控制器中单独设置每个页面标题,如下所示:
渲染的标题将如下所示:
哦,您需要在标签所在的布局脚本中使用此内容:
You should look into the
headTitle
view helper. You can put this snippet below in your bootstrap file (from the documentation at http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.headtitle).Then you can set each page title individually in controller like this:
The rendered title will look like this:
Oh, and you need this in your layout script where the tag would go:
研究使用 布局 和 占位符。布局适用于您的所有视图,您可以在那里设置标题。然后,您可以在控制器中将“主页”或“仪表板”部分设置为布局将使用的占位符。
Look into using layouts and placeholders. Layouts are applied to all your views, you can set the title there. In your controller you can then set the "home" or "dashboard" part to a placeholder that will be used by your layout.
在 Bootstrap.php 中
在任何 view/.phtml 中
In Bootstrap.php
In any view/.phtml
这是将页面标题设置到控制器中的最佳方法。如果您想设置新标题,则使用..
如果您想在标题前添加现有标题,则使用
This is best way to set page title into the controller. If you want to set new title then use..
If you want to prepend the title with existing title then use
我认为你可以使用js来做到这一点,因为你只需将标题=TestProject设置为站点,然后在每个页面中你可以使用javascript读取标题,然后连接额外的标题
,如果你使用的是母版页之类的东西
I think you may do this with js as you just site the title =TestProject only then in each page you could with javascript read the title then concatenate the extra title
this if you are using something like master pages