mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-06 01:31:22 +02:00
* First cut * Temporarily disable composer.json for netlify build * POC * New recursive directory query, various refinements * Fix flexbox * new styled components plugin * Apply frontmatter delimiters * Mobile styles, animation * Search * Redesign, clean up * Nuke the cache, try again * fix file casing * Remove production env file * ID headers * Move app to new repo * Add frontmatter universally * Hide children changelogs * Add how to title * New callout tags * Revert inline code block change * Replace note callouts * Fix icons * Repalce images * Fix icon * Fix image links * Use proper SQL icon
93 lines
2.2 KiB
Markdown
93 lines
2.2 KiB
Markdown
---
|
|
title: SiteConfig
|
|
summary: Content author configuration through the SiteConfig module.
|
|
icon: laptop-code
|
|
---
|
|
|
|
# SiteConfig
|
|
|
|
The `SiteConfig` module provides a generic interface for managing site-wide settings or functionality which is used
|
|
throughout the site. Out of the box, this includes setting the site name and site-wide access.
|
|
|
|
## Accessing variables
|
|
|
|
`SiteConfig` options can be accessed from any template by using the $SiteConfig variable.
|
|
|
|
|
|
```ss
|
|
$SiteConfig.Title
|
|
$SiteConfig.Tagline
|
|
|
|
<% with $SiteConfig %>
|
|
$Title $AnotherField
|
|
<% end_with %>
|
|
```
|
|
|
|
To access variables in the PHP:
|
|
|
|
|
|
```php
|
|
use Silverstripe\SiteConfig\SiteConfig;
|
|
|
|
$config = SiteConfig::current_site_config();
|
|
|
|
echo $config->Title;
|
|
|
|
// returns "Website Name"
|
|
```
|
|
|
|
## Extending SiteConfig
|
|
|
|
To extend the options available in the panel, define your own fields via a [DataExtension](api:SilverStripe\ORM\DataExtension).
|
|
|
|
**app/code/extensions/CustomSiteConfig.php**
|
|
|
|
|
|
```php
|
|
use SilverStripe\Forms\FieldList;
|
|
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
|
|
use SilverStripe\ORM\DataExtension;
|
|
|
|
class CustomSiteConfig extends DataExtension
|
|
{
|
|
|
|
private static $db = [
|
|
'FooterContent' => 'HTMLText'
|
|
];
|
|
|
|
public function updateCMSFields(FieldList $fields)
|
|
{
|
|
$fields->addFieldToTab("Root.Main",
|
|
new HTMLEditorField("FooterContent", "Footer Content")
|
|
);
|
|
}
|
|
}
|
|
```
|
|
|
|
Then activate the extension.
|
|
|
|
**app/_config/app.yml**
|
|
|
|
|
|
```yml
|
|
Silverstripe\SiteConfig\SiteConfig:
|
|
extensions:
|
|
- CustomSiteConfig
|
|
```
|
|
|
|
[notice]
|
|
After adding the class and the YAML change, make sure to rebuild your database by visiting http://example.com/dev/build.
|
|
You may also need to reload the screen with a `?flush=1` i.e http://example.com/admin/settings?flush=1.
|
|
[/notice]
|
|
|
|
You can define as many extensions for `SiteConfig` as you need. For example, if you're developing a module and want to
|
|
provide the users a place to configure settings then the `SiteConfig` panel is the place to go it.
|
|
|
|
## API Documentation
|
|
|
|
* [SiteConfig](api:SilverStripe\SiteConfig\SiteConfig)
|
|
|
|
|
|
## Related Lessons
|
|
* [DataExtensions and SiteConfig](https://www.silverstripe.org/learn/lessons/v4/data-extensions-and-siteconfig-1)
|