如何自定义 <title>
SilverStripe 页面数?
现在是
<title><% if $MetaTitle %>$MetaTitle<% else %>$Title<% end_if %> » $SiteConfig.Title</title>
最佳答案
您当前的页面模板页<title>
标签是:
<title>
<% if $MetaTitle %>$MetaTitle<% else %>$Title<% end_if %>
» $SiteConfig.Title
</title>
您可以更改此设置以使用您想要的任何变量或内容。
您当前的模板代码检查页面是否有 $MetaTitle
定义的。如果确实如此,它将使用这个。否则它将使用页面 $Title
.
最后一部分添加网站标题 $SiteConfig.Title
到最后。该字段可以在 CMS 的“设置”选项卡上找到。
MetaTitle
变量已从 3.1 中的核心 SilverStripe 代码中删除。如果您想重新添加此功能,可以通过安装 SilverStripe MetaTitle module 来完成此操作。或者自己将变量和输入添加到 Page 类中。
这里是一些添加 MetaTitle
的代码变量为 Page
类:
class Page extends SiteTree {
private static $db = array(
'MetaTitle' => 'Varchar(255)'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab(
'Root.Main',
TextField::create('MetaTitle')
->setRightTitle('Shown at the top of the browser window and used as the "linked text" by search engines.')
->addExtraClass('help'),
'MetaDescription'
);
return $fields;
}
}
该变量将出现在 CMS 中每个页面 Content
下方。字段。
关于silverstripe - 如何自定义 SilverStripe 页面的 <title>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32305730/