silverstripe - 如何自定义 SilverStripe 页面的 <title>

标签 silverstripe

如何自定义 <title> SilverStripe 页面数?

现在是

<title><% if $MetaTitle %>$MetaTitle<% else %>$Title<% end_if %> &raquo; $SiteConfig.Title</title>

最佳答案

您当前的页面模板页<title>标签是:

<title>
    <% if $MetaTitle %>$MetaTitle<% else %>$Title<% end_if %> 
    &raquo; $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 页面的 &lt;title&gt;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32305730/

相关文章:

php - Silverstripe URL 如何工作?

silverstripe - 如何将自定义项添加到左侧 CMS 菜单并管理模型和额外字段?类似于 ModelAdmin?

Silverstripe $many_many 关系与关系上的一个属性

jquery - 默认情况下在 Silverstripe 的 ModelAdmin 中显示过滤器表单

Silverstripe 3.1 更改 Gridfield 添加按钮的默认按钮文本?

php - Silverstripe TinyMCE 在负载均衡器后面崩溃。

php - Silverstripe 扩展 Controller 操作

silverstripe - 我可以动态更改 SilverStripe 主题吗?

php - Silverstripe - 检索数组中的 POST 数组

database - SilverStripe CMS 取消发布,无需用户交互