0

So, what can I say? How do I go about adding a page programmatically in MURA CMS? Preferably version 6.1.

I am building a plugin that needs to create a couple of pages in the Site Manager. I want to add this routine in the 'install' method of the 'plugin/plugin.cfc' component.

I have been unable to find any pointers to this on line, which, perhaps, means this particular issue cannot be resolved. But, I live in hope.

Thanks people, in advance, for any help on this one.

Charles Robertson
  • 1,760
  • 16
  • 21

1 Answers1

3

When you add content to Mura, the key is that you'll need to know the parentid of where you wish the new content item(s) to live. Other than that, Mura offers an easy way perform CRUD operations on content items. You can read more about it at http://docs.getmura.com/v6/back-end/base-mura-objects-beans/loading-beans/ (based on the version you've specified). I'd also like to point out that the documentation has been greatly expanded in the latest version which can be found at http://docs.getmura.com/v7/mura-developers/mura-beans-objects/common-bean-objects/content-bean/. While the concepts and syntax still apply to older version, some newer methods for working with Mura content objects have been added since v6.1. I also highly recommend upgrading soon, as v7.1 is about to be released as well (as of Feb. 2018).

That said, the only two required fields/attributes are title and parentid. Here's the basic code for being able to do what you need:

// load the parent content item
parentBean = $.getBean('content').loadBy(title='Home');

// you may want to verify the `parentBean` actually exists before proceeding
if ( parentBean.getIsNew() ) {
  Throw(message='parentBean does NOT exist!');
}

// v6.1 syntax
newBean = $.getBean('content')
           .setValue('title', 'Some Title')
           .setValue('parentid', parentBean.getContentID())
           .save();

// v7.0+ syntax
newBean = $.getBean('content')
           .set('title', 'Some Title')
           .set('parentid', parentBean.get('contentid'))
           .save();

// after saving, you can check for errors
if ( !StructIsEmpty(newBean.getErrors()) ) {
  WriteDump(var=newBean.getErrors(), abort=true);
}

You could clearly set other attributes (as defined in the earlier links) as well, if desired.

Cheers!

  • Thanks so much for this information. It is exactly what I was looking for. I am afraid I cannot upgrade because I am using, the much underrated, Advertising module. I have built a plug-in around it, so I would be binning a years worth of work! – Charles Robertson Feb 15 '18 at 18:01
  • Just out of interest, is there a key for adding display objects via the Layout & Objects tab, programmatically. I want to add an Ad Zone region to a page during its creation? Thanks... – Charles Robertson Feb 15 '18 at 18:08
  • I saw that one of the keys was 'objectparams'. Does this represent 'content objects' in 'Layout & Objects'? – Charles Robertson Feb 15 '18 at 18:15