We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29635
    • 361 Posts
    I just threw together a quick plugin to replace all "orphan" (invalid) & characters to & (ampersands). It will leave alone any HTML entity like   or – or etc, but it will convert & to &

    This is useful if your users enter a pagetitle like "News & Press", which Wayfinder will output exactly as that, without HTML encoding it first. This leaves your code invalid, and is kind of a pain to fix manually.

    If anybody finds this useful or has any other ideas to enhance it please let me know. There might be something that does this already, but I couldn’t find it. Let me know if so. (It also contains a line to change ].]> to ]]>, which is useful if you’re using PHx and CDATA tags, mentioned in another thread.)
    //<?php
    // Begin plugin code
    $e = &$modx->event;
    
    $id = $modx->event->params['id'];
    
    if ($e->name == 'OnWebPagePrerender') {
    	$o = &$modx->documentOutput; // get a reference of the output
    	// Replace all ^text inside hats^ to <sup> tags, useful for more friendly Wayfinder replacements
    	$o = preg_replace('%\^([()a-zA-Z0-9 ]*)\^%i', "<sup>$1</sup>",$o);
    	// Replace orphan & with &
    	$o = preg_replace('%&(?![a-zA-Z0-9#]{1,6})%i', "&",$o);
    	// Replace ].]> with ]]>, useful for CDATA tags inside PHx calls: http://modxcms.com/forums/index.php?topic=31435.0
    	$o = str_replace('/* ].]> */', '/* ]]> */',$o);
    }
    
    $e->output($o);
    return '';
      Need MODx Ecommerce? Try FoxyCart!
      • 7231
      • 4,205 Posts
      Fantastic, thanks grin I have been thinking about this for a while, happy to know I no longer need to think about it wink
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don&#39;t know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 20413
        • 2,877 Posts
        Very nice!! Thanks. smiley

        Ive been using this method ---> http://modxcms.com/forums/index.php/topic,30867.msg187342.html#msg187342
          @hawproductions | http://mrhaw.com/

          Infograph: MODX Advanced Install in 7 steps:
          http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

          Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
          http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
          • 26931
          • 2,314 Posts
          it’s working perfectly! thank you smiley

          j
            • 7231
            • 4,205 Posts
            // Replace all ^text inside hats^ to <sup> tags, useful for more friendly Wayfinder replacements
            	$o = preg_replace('%\^([()a-zA-Z0-9 ]*)\^%i', "<sup>$1</sup>",$o);
            I don’t understand this. What are hats and how does this help with WF replacements? Don’t want to miss out on something cool rolleyes
              [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

              Something is happening here, but you don&#39;t know what it is.
              Do you, Mr. Jones? - [bob dylan]
              • 29635
              • 361 Posts
              Quote from: dev_cw at Dec 30, 2008, 07:06 AM

              // Replace all ^text inside hats^ to <sup> tags, useful for more friendly Wayfinder replacements
              	$o = preg_replace('%\^([()a-zA-Z0-9 ]*)\^%i', "<sup>$1</sup>",$o);
              I don’t understand this. What are hats and how does this help with WF replacements? Don’t want to miss out on something cool  rolleyes
              I just left it in there from the last site I used this on. Expand the "team" section and see how the (pro) and (am) are superscript? I did it this way so Wayfinder (and all chunks and TVs and such) would do the correct superscript tags, but the <title> tag has a quick bit of PHx to strip the ^ out:
              <?php
              $output = str_replace('^','',$output);
              return $output;
              ?>

              I’m sure there are better ways to make this happen, but this works well enough. I don’t generally like using more than a single title for a page (just pagetitle, rarely any longtitle or menutitle), so this worked out well. The title attribute on the Wayfinder links get the <sup> in there, and it could be fixed, but I doubt anybody would need that little bit anyway so it’s probably best just to strip out of the plugin.
                Need MODx Ecommerce? Try FoxyCart!