Displaying placeholders and snippet calls

This is the plugin Brackify, which i use to display placeholders, snippet calls etc in the examples in the Ditto section. If you have [+placeholder+] as normal in your text, the element will be parsed by MODx. Entering a space between the bracket and the plus sign or other punctuation, thus: [ +placeholder+ ], avoids parsing, and the space is removed by the plugin when the page is output.

  1. $e = &$modx->Event;
  2. if ($e->name == "OnWebPagePrerender"){
  3.     $page = $modx->documentOutput;
  4.     $brackets = '[ (,) ],[ [,] ],[ !,! ],[ +,+ ],[ *,* ]' ;
  5.     $despaced = str_replace(' ','',$brackets);
  6.     $search = explode(',',$brackets);
  7.     $replace = explode (',',$despaced);
  8.     $page = str_replace($search,$replace,$page);
  9.     $page = str_replace('/home/myServerAccount/public_html/','[(base_path)]',$page);
  10.     $modx->documentOutput = $page;
  11. }

You could usefully add double curly braces to the list in line 4 to cater for chunks. Line 9 substitutes [(base_path)] for the actual path to my WWW directory on the server, restoring what was in the original code and hiding my server account information.

Note there's no <?php and ?> pair in a plugin. Also that OnWebPagePrerender has to be checked in the System Events tab.