We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33657
    • 128 Posts
    is this ok for 2.1? its no longer working, trying to figure out what is bad about it.. i’m looking over the depreciated code and i don’t see what I need to change?
    function delete_template_nodes($delete_node,$preserve_node) {
    
    	global $modx; // Without this, the $modx var is out of scope.
    	$delete_node = preg_quote($delete_node);
    	$pattern = '/\<'.$delete_node.'\>(.*)\<\/'.$delete_node.'\>/Usi';
    	$modx->documentOutput = preg_replace($pattern,'',$modx->documentOutput);
    	$preserve_node = preg_quote($preserve_node);
    	$pattern = '/\<'.$preserve_node.'\>/Usi';
    	$modx->documentOutput = preg_replace($pattern,'',$modx->documentOutput);
    	$pattern = '/\<\/'.$preserve_node.'\>/Usi';
    	$modx->documentOutput = preg_replace($pattern,'',$modx->documentOutput);
    }

      • 22303 MODX Staff
      • 10,725 Posts
      What event is this attached to? That will only work with OnParseDocument in 2.1, but I don’t think that is the correct event for what you are attempting here. I believe you want to use $modx->resource->_output instead of $modx->documentOutput if you are using OnWebPagePrerender. The documentOutput variable probably should have been removed completely for 2.1, but I’m not sure an appropriate replacement has been realized yet.
        • 33657
        • 128 Posts
        Quote from: OpenGeek at May 27, 2011, 12:29 PM

        What event is this attached to? That will only work with OnParseDocument in 2.1, but I don’t think that is the correct event for what you are attempting here. I believe you want to use $modx->resource->_output instead of $modx->documentOutput if you are using OnWebPagePrerender. The documentOutput variable probably should have been removed completely for 2.1, but I’m not sure an appropriate replacement has been realized yet.

        yes this is for OnWebPagePrerender (which works for 2.1 and my 2.0.8 to 2.1 tests show it working as well)

        so would the rewrite be??
        <?php
        function delete_template_nodes($delete_node,$preserve_node) {
        
        	global $modx; // Without this, the $modx var is out of scope.
        	$delete_node = preg_quote($delete_node);
        	$pattern = '/\<'.$delete_node.'\>(.*)\<\/'.$delete_node.'\>/Usi';
        	$modx->resource->_output = preg_replace($pattern,'',$modx->resource->_output);
        	$preserve_node = preg_quote($preserve_node);
        	$pattern = '/\<'.$preserve_node.'\>/Usi';
        	$modx->resource->_output = preg_replace($pattern,'',$modx->resource->_output);
        	$pattern = '/\<\/'.$preserve_node.'\>/Usi';
        	$modx->resource->_output = preg_replace($pattern,'',$modx->resource->_output);
        }

          • 22303 MODX Staff
          • 10,725 Posts
          Correct.
            • 33657
            • 128 Posts
            Quote from: OpenGeek at May 27, 2011, 12:56 PM

            Correct.

            That worked!!! thanks! I posted a "new" extra when I should have upgraded my extra... i then went back and corrected it and upgraded it, but now we have 2 in the system... will the moderators figure it out? or am I doomed! smiley