Page 1 of 1
[SOLVED] How to create a page using API?
Posted: Thu Apr 09, 2015 8:19 am
by Augustas
Hello,
maybe someone could share a code which creates a Page programmatically and assigns a template to it?
Thank you
Augustas
Re: How to create a page using API?
Posted: Thu Apr 09, 2015 9:12 am
by Jos
Re: How to create a page using API?
Posted: Thu Apr 09, 2015 9:22 am
by Augustas
Thank you Jos for the effort, I saw this topic, but it has no information I need.
calguy1000 just mentions that
"There is lots of documentation in the API docs"
and
"Creating content pages is a bit more complicated, but not by much."
and then he gives some hints for CMSMS 2.0 users, while I am working with 1.11.X
Re: How to create a page using API?
Posted: Thu Apr 09, 2015 3:28 pm
by calguy1000
This is 2.0 code. The 1.x code is similar (there is no concept of a design).
$contentobj = new Content;
$contentobj->SetName('Test Page');
$contentobj->SetAlias();
$contentobj->SetMenuText('Test Page');
$contentobj->SetPropertyValue('searchable',1);
$contentobj->SetPropertyValue('design_id',$design_id);
$contentobj->SetTemplateId($template_id);
$contentobj->SetOwner(1);
$contentobj->SetParentId(-1);
$contentobj->SetActive(TRUE);
$contentobj->SetShowInMenu(TRUE);
$contentobj->SetCachable(TRUE);
$contentobj->SetPropertyValue('content_en',$some_html);
$contentobj->Save();
You will need to update the hierarchy positions after creating a new page programattically. but that is a simple method in the contentoperations class
Re: How to create a page using API?
Posted: Sat Apr 11, 2015 8:57 am
by Augustas
That's useful, thank you.