We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21255
    • 215 Posts
    In my templates I’m using the [*longtitle*]-tag - but my customers persistently refused to fill out the corresponding field in manager while creating new documents. laugh
    So I wrote the following Plugin, that uses pagetitle as longtitle, if longtitle is empty.

    (To use it, create a new Plugin, name it whatever you want, paste the code below and make sure, OnParseDocument flag is set in system events tab.)

    $e = &$modx->Event;
    
    switch($e->name) {
    
      case 'OnParseDocument':
        if(!$modx->documentObject['longtitle']) {
          $modx->documentObject['longtitle'] = $modx->documentObject['pagetitle'];
        }
        break;
    
      default:
        return;
        break;
    
    }
    
    • Cool plugin, netnoise! cool That is a godsend (I’m notorious for forgetting the longtitle)

      Thanks, Garry
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 5683
        • 96 Posts
        Thanks netnoise! This is a much needed plugin: also my users always forget to set the longtitle!

        BTW, I think that the best event to capture is "OnDocFormSave" (or maybe "OnBeforeDocFormSave"), because it is raised only once, when the page is saved, and not every time the page is rendered... however, simply capturing this event doesn’t work. The problem could be that, in this case, you shouldn’t modify the documentObject, but something else.

        Any clue from the core team will be appreciated!
          • 19726
          • 239 Posts
          I made a AutomaticLongTitle plugin in the past the uses the OnDocFormSave event. The problem is indeed that it is not possible to update the document object. For the plugin see http://modxcms.com/forums/index.php/topic,1956.msg14246.html#msg14246
            • 5683
            • 96 Posts
            Good idea, Mitch! grin
            Thank you!