Last active
February 26, 2016 01:43
-
-
Save bajanReece/5186538 to your computer and use it in GitHub Desktop.
How to programatically create new content with Concrete5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$my_page_type = 'php_news'; | |
$parent_path = '/languages/php/news'; | |
$hide_from_nav = TRUE; | |
$parent = Page::getByPath($parent_path); | |
/** | |
* Let's pretend the title and description have been set by POST values | |
* and added to the variables $title, $description and $content | |
**/ | |
$ct = CollectionType::getByHandle($my_page_type); | |
$data = array('cName' => $title, | |
'cDescription' => $description, | |
'uID'=>$current_user_id | |
); | |
/** | |
* Other values possible in data are: | |
* "uID": User ID of the page's owner | |
"pkgID": Package ID the page belongs to | |
"cName": The name of the page | |
"cHandle": The handle of the page as used in the path | |
"cDatePublic": The date assigned to the page | |
**/ | |
if(is_object($parent) && is_numeric($parent->cID)) $p = $parent->add($ct, $data); | |
// We can add attributes | |
if($hide_from_nav){ | |
// Collection Attribute Key Exclude from Navigation | |
$cakExNav = CollectionAttributeKey::getByHandle('exclude_nav'); | |
$cakExNav->setAttribute($p, true); | |
} | |
// You can now add block content | |
$bt = BlockType::getByHandle('content'); | |
$pdata = array('content' => $content); | |
$p->addBlock($bt, 'Main', $pdata); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment