We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22629
    • 194 Posts
    I’ve been trying to get a simple plugin put together; I’ve searched high and low but cannot find any documentation explaining how to start new plugins from scratch, and where the document info is placed.

    Basically I have a section of my site under a single folder, which is a sort of blog, sorted into folders, and a document for the entries - e.g. September 6th would be in /blog/2007/september/06.

    What I want to do is create a document under the ultimate parent of /blog, fill only the subtitle in with the title of the blog entry, then when it’s saved, a plugin automatically fills in the menu title and alias as the current date (e.g. 06), and the title as the current date in a string (e.g. 6th September, 2007.)

    If the saved document is a container, then fill in the month-name as the alias and menu title.

    I’ve tried the following plugin:

    switch($modx->Event->name) 
    {
    	case 'OnBeforeDocFormSave':
    		$modx->documentObject['content'] = date("d/m/Y H:i:s");
    		break;
    	case 'OnDocFormSave':
    		$modx->documentObject['content'] = date("d/m/Y H:i:s");
    		break;
    	default:
    		return;
    		break;
    }


    to set the document’s content to the current date, but when the document is saved, the content is still empty.

    I know I could do this in the front-end with snippets based on the document’s published date, but then I’d just get lots of "Untitled documents" in the manager, and I’d rather not have to put this information into every document - it’d be much quicker to only have to type the content of the document and a title (plus I usually forget one or two details and have to go back and change them!)

    What I’m looking for is what variables I can use in my plugins, what they represent, and how they’re used my MODx to interact with documents; I can’t find any information anywhere.

    Any suggestions?

    Thanks.

    Andy.
      Andy Shellam | www.networkmail.eu | @Pandy06269 @NetworkMail

      modx Revolution 2.2.6
      Windows 2012 | IIS 8 | php 5.4.11 | MySQL 5.5.29

      Content-Managed Websites Built on MODX
      • 22629
      • 194 Posts
      Also I looked at the InheritParentTemplate plugin as it does a similar thing (but before the document form is rendered) and looked at the line:

      $content[’template’] = $parent[’template’];

      This suggests that $content is a reference to the modx documentObject (as template is the document’s defining template.) However if I do:

      global $content;
      $content['content'] = "test";


      the content is saved written out as "Array".

      Any advice would be greatly appreciated!
        Andy Shellam | www.networkmail.eu | @Pandy06269 @NetworkMail

        modx Revolution 2.2.6
        Windows 2012 | IIS 8 | php 5.4.11 | MySQL 5.5.29

        Content-Managed Websites Built on MODX