Subscribe: RSS
  • Hi,
    perhaps some of the developers can give me a quick hint. If I don´t want the document parser to render MODx tags in <pre> or <code> or some self defined tags, how would be the best practice? Or how is it realised here on the modx documentation page? On my german site I want to create some tutorials and also in the integrated forum the parser doesn´t allow to write MODx tags like snippet calls and so on. Of course it´s possible to insert an HTML comment, but that is not very usable.

    So, how is this made on the documentation site or what do I have to change in the

    Thx in advance,
    • Okay, did it myself by editing the If someone needs it:

      	function evalSnippets($documentSource) {
      	//added by mmd for not parsing <pre> tags part 1
      		preg_match_all('~\<pre>(.*?)\</pre>~', $documentSource, $fragments); //looking for <pre> tags, store them in $fragments
      		if ($fragmentsCount=count($fragments[1])) {
      				for($i=0; $i<$fragmentsCount; $i++) {
      					$fragments_replace[1][$i] = str_replace('[[','[*#[',$fragments[1][$i]); //replace snippet calls within
      					$fragments_replace[1][$i] = str_replace(']]',']*#]',$fragments[1][$i]); //<pre> tags with other chars
      					$documentSource = str_replace($fragments[1][$i],$fragments_replace[1][$i],$documentSource);
      	//end part 1
      		preg_match_all('~\[\[(.*?)\]\]~', $documentSource, $matches);
      		$etomite = &$this;
                      //added by mmd for not parsing pre tags part 2
      		$documentSource = str_replace('[*#[','[[',$documentSource); //replace snippet placeholders 
      		$documentSource = str_replace(']*#]',']]',$documentSource); //with original
                     // end part 2
      		return $documentSource;

      • Cute solution. You can turn your hack into a plugin, by making the first substitution on an early stage of the parsing process (for example, in response to a OnLoadWebDocument event), and the second one after the snippets have been evaluated, for example capturing the OnWebPagePrerender event.
        • a simple solution is to use HTML comments to break up the brackets in you snippet call. that way it wont be parsed.

          an example you ask! ok:

          [<!-- -->[DropMenu]<!-- -->]

          would be displayed on the page as [[DropMenu]], but would not be parsed by MODx


            Husband, Father, Brother, Son, Programmer, Atheist, Nurse, Friend, Lover, Fighter.
            All of the above... in no specific order.

            I send pointless little messages
          • Quote from: ScottyDelicious at Apr 28, 2006, 06:15 PM

            [<!-- -->[DropMenu]<!-- -->]
            That’s how I do it at the moment ... but a plugin would be kinda nice grin
              Garry Nutting
              Senior Developer
              MODX, LLC

              Twitter: @garryn
            • If anybody still needs this a year later, try my solution:


              • Please create a thread for your plugin in "in development" forums and once it’s tested post to the resource repository.. Thanks a lot for contributing! Nice job!

                  "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                • How bout using to plugin to literally "Remove" everything within <pre> tags and set a placeholder with the content? This seems like a cleaner solution to me and less of a "hack"
                  /** System Events Selected: OnParseDocument */
                  /** Strip out $source in favor of a placeholder */
                  if (!function_exists('replace_pre_tags')) {
                  function replace_pre_tags($source) {
                  	if (is_array($source)) $source = $source[0];
                  	static $counter = 1;
                  	static $in = array('[', ']');
                  	static $out = array('[', ']');
                  	$source = str_replace($in, $out, $source);
                  	$ph = 'pre_content_'.$counter++;
                  	$modx->setPlaceholder($ph, $source);
                  	return '[+'.$ph.'+]';
                  // Run the replacements
                  preg_replace_callback('~\<pre>.*?\</pre>~', 'replace_pre_tags', $modx->documentOutput);
                  On second thought, you wouldn’t really even need to replace the whole tag with a placeholder... But oh well, have fun!
                  • I created an "in development" thread as requested.


                    • I don’t know a lot about MODx internals, but presumably you are simply saving all the content enclosed within <pre></pre> tags, and restoring it just before it’s sent to the web client. If so, then I see no reason why it won’t work. But we do need to use some tag other than <pre>. Otherwise you still won’t be able to mention [!Wayfinder!] in the middle of a normal paragraph.

                      Either way, yours or mine, we seem to be copying large amounts of data. It could end up slowing down the system a lot.