Within SiteConfig
there is a TextField
Site title. I'm trying to change the label of this textfield $titleField
through a SiteConfig extension in class SiteConfigExtension extends DataExtension
.
Here is the code from siteconfig/code/model/ where it's created:
$fields = new FieldList(
new TabSet("Root",
$tabMain = new Tab('Main',
$titleField = new TextField("Title", _t('SiteConfig.SITETITLE', "Site title")),
....
Q: What's the easiest way to replace the SiteTitle label without having to remove the field in the SiteConfig extension and re-add it again with the desired label?
Updating the title from SiteConfigExtension uses updateCMSFields...
class SiteConfigExtension extends DataExtension {
public function updateCMSFields(FieldList $fields) {
if ($titleField = $fields->dataFieldByName('Title'))
$titleField->setTitle('my title');
}
}
You could make use of the implemented _t()
function. Put following in your mysite/lang/{LANG_CODE}.yml
file:
{LANG_CODE}:
SiteConfig:
SITETITLE: 'My new title'
Replace {LANG_CODE}
with the admin language(s) being used (eg sv
for Swedish, or en
for English). Keeping your strings separated from the code comes with many benefits. Remember to run ?flush
after updating YAML files.