We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22815
    • 1,097 Posts
    Posting here for feedback before I tidy it up and add it to the Repo.

    In a wiki, you can add a new document simply by ’visiting’ the non-existant page, eg http://en.wikipedia.org/wiki/Newpagename and clicking on "Start the Newpagename article", or similar.
    In MODx’s QuickEdit front-end editing facility, one of the few things you can’t do is create a new page.
    Visiting /newpagename.html gets the 404 page.

    So, enter LinkToCreatePage. By adding this snippet, and adding the call [!LinkToCreatePage!] to your 404 page, whenever a logged in manager types in a page URL for a page that doesn’t exist, they’ll get the option to create a page.

    In fact, in the default snippet, you get three options. You’ll need to change these to reflect your requirements. Sorry this isn’t more newbie-friendly, but this is the way that makes sense for me:
    $output = '<br /><a href="'.$_GET['q'].'?createpage&template=paulgregory&parent=0">Create ' . $pagename . ' as standard page</a>';
    $output .= '<br /><a href="'.$_GET['q'].'?createpage&template=paulgregory&parent=51">Create ' . $pagename . ' as news post</a>';
    $output .= '<br /><a href="'.$_GET['q'].'?createpage&template=blog&parent=2">Create ' . $pagename . ' as blog post</a>';
    

    You will need to change the template and parent values to suit your site.

    Yes, I could have had a drop-down of page parents and a drop-down of templates, but in my experience they tend to be related and it’s easier for the admin to designate the types of pages that managers can create. Frankly I’d rather get a QuickEdit/front-end-based template & parent changer; so I could add a page and then move it - this seems more useful.

    This requires the DocManager API which you can get from http://modxcms.com/Docmanager-881.html
    (I tried DocAPI but had trouble setting the alias).

    It also requires Friendly URLs to be on. I’m not sure whether this will work with paths; probably not.

    Tested with 0.9.5 but should work with 0.9.2.1 fairly happily.

    // LinkToCreatePage - enables Manager users to add a page from the front-end by typing the URL in - a bit like in a Wiki.
    // Requires DocManager API : http://modxcms.com/Docmanager-881.html
    // v0.2 by Paul Gregory
    // To use, add [!LinkToCreatePage!] to your 404 page.
    // Be sure to change the template= and parent= values in the URLs at the bottom of this snippet to those appropriate for your site.
    
    $pagename = substr($_GET['q'],0,strpos($_GET['q'],'.'));
    $pagename = str_replace($modx->config['friendly_url_prefix'],"",$pagename);
    $pagename = str_replace($modx->config['friendly_url_suffix'],"",$pagename);
    
    $parent = $_GET['parent'];
    $template = $_GET['template'];
    if(isset($_SESSION['mgrValidated'])) {
    	if(isset($_GET['createpage'])) {
    		require_once('assets/libs/docmanager/document.class.inc.php');
    		$doc = new Document();
    		$doc->Set('parent',$parent);
    		$doc->Set('alias',$pagename);
    		$title = str_replace("-"," ",$pagename);
    		$doc->Set('pagetitle',$title);
    		$doc->Set('content','New document');
    		$doc->Set('template',$template);
    		$doc->Save();
    		// Following cribbed from docapi by Wendy Novianto:
    		include_once($base_path.'manager/processors/cache_sync.class.processor.php');
    		$sync = new synccache();
    		$sync->setCachepath($base_path."assets/cache/");
    		$sync->setReport(false);
    		$sync->emptyCache();
    		$output = '<br /><a href="' . $_GET['q'] . '">Click here to see the created page.</a>';
    	}
    	else {
    		$output = '<br /><a href="'.$_GET['q'].'?createpage&template=paulgregory&parent=0">Create ' . $pagename . ' as standard page</a>';
    		$output .= '<br /><a href="'.$_GET['q'].'?createpage&template=paulgregory&parent=51">Create ' . $pagename . ' as news post</a>';
    		$output .= '<br /><a href="'.$_GET['q'].'?createpage&template=blog&parent=2">Create ' . $pagename . ' as blog post</a>';
    	}
    } else {
    // $output = '<br />You tried : ' . $_GET['q'];
    }
    return $output;
    
      No, I don&#39;t know what OpenGeek&#39;s saying half the time either.
      MODx Documentation: The Wiki | My Wiki contributions | Main MODx Documentation
      Forum: Where to post threads about add-ons | Forum Rules
      Like MODx? donate (and/or share your resources)
      Like me? See my Amazon wishlist
      MODx "Most Promising CMS" - so appropriate!
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Great idea! I have long wished for the ability to either create a new document in the same folder, or (even better to my thinking) to duplicate the open document so the user only needs to edit what needs to be different (pagetitle, menutitle, content, etc) while the rest of the document will be consistant with the section he’s working in.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org