Skip to content

Commit

Permalink
DOCS Added 'Modifying Meta Tags' entry
Browse files Browse the repository at this point in the history
  • Loading branch information
jonom committed Feb 1, 2019
1 parent d4e322b commit 0cbc02a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/en/02_Developer_Guides/01_Templates/02_Common_Variables.md
Expand Up @@ -143,6 +143,27 @@ $MetaTags(false)
<title>$Title - Bob's Fantasy Football</title>
```

### Modifying Meta Tags

You can override the `MetaComponents()` method on your `SiteTree` sub-classes or make use of the `MetaComponents` extension point to manipulate the underlying data that is rendered by `$MetaTags`. Example (for `Page` class):

```php
public function MetaComponents()
{
$tags = parent::MetaComponents();
// Override the content of the Title tag (needs to be html)
if ($this->MetaTitle) {
$tags['title']['content'] = $this->obj('MetaTitle')->forTemplate();
}
// Provide a default Meta Description
if (!$tags['description']['attributes']['content']) {
// provide raw text as attributes will be escaped later
$tags['description']['attributes']['content'] = $this->dbObject('Content')->LimitCharactersToClosestWord(300);
}
return $tags;
}
```

## Links

```ss
Expand Down

0 comments on commit 0cbc02a

Please sign in to comment.