Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Last active December 14, 2023 10:19
Show Gist options
  • Save stevewithington/e722ebfc59657ea4177c to your computer and use it in GitHub Desktop.
Save stevewithington/e722ebfc59657ea4177c to your computer and use it in GitHub Desktop.
Mura CMS : How to create content dynamically in Mura. There are two primary pieces to the puzzle: 1) Mura needs to know where to add the content. Specifically, it needs to know the ParentID. 2) Remember, there's only one required field when adding content via the UI, and that's the 'Title' field. To do this dynamically, I usually recommend also …
<cfscript>
// This Gist is very much related directly to https://gist.github.com/stevewithington/4742829 on how to import content via RSS.
// However, this is the main code
content = $.getBean('content').loadBy(remoteid = 'PrimaryKeyFromExternalDB');
content.setTitle('theTitle');
content.setMenuTitle(''); // we clear the other title fields so that Mura will auto-generate them based on the actual 'title'
content.setURLTitle('');
content.setHTMLTitle('');
content.setApproved(1);
content.setIsNav(0);
content.setParentID('theContentIdOfTheParent');
content.setRemoteID('PrimaryKeyFromExternalDB');
// you could set any other attributes before saving as well such as the body
content.setBody('<p>whatever you want</p>');
content.save();
// handle any errors!
if ( !StructIsEmpty(content.getErrors()) ) {
WriteDump(var=content.getErrors(), abort=true);
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment