Create Cms Page from PHP code
9
Use this code to programatically create a CMS Page with URL/Title translations:
$page = new \Cms\Classes\Page([
'fileName' => 'test-page',
'title' => 'My Page Title',
'url' => '/test-page',
'layout' => 'default',
]);
$page->attributes['viewBag'] = [
'localeUrl' => [
'fr' => '/french-URL',
'de' => '/deutch-URL',
],
'localeTitle' => [
'fr' => 'French Title',
'de' => 'Deutch Title',
],
];
$page->save();
(Note: to be used with Rainlab.Translate
plugin)
Use this code to programatically create a CMS Page and attach a component:
$page = new \Cms\Classes\Page([
'fileName' => 'test-page',
'title' => 'My Page Title',
'url' => '/test-page',
'layout' => 'default',
]);
$page->attributes['myComponent'] = [];
$page->save();
There are no comments yet
Be the first one to comment