We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32963
    • 1,732 Posts
    Hi Susan,

    Very cool additions indeed.

    PS. Is it a plugin or a snippet?
      xWisdom
      www.xwisdomhtml.com
      The fear of the Lord is the beginning of wisdom:
      MODx Co-Founder - Create and do more with less.
    • Plugin. Hooked to the OnWebPagePrerender event. Sorry, thought I said that in the first place!
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 32963
        • 1,732 Posts
        Quote from: sottwell at Oct 31, 2005, 06:29 AM

        Plugin.  Hooked to the OnWebPagePrerender event.  Sorry, thought I said that in the first place!

        Cool. Didn’t see the Plugin part only saw the the changes made to "FlexSearchForm"
          xWisdom
          www.xwisdomhtml.com
          The fear of the Lord is the beginning of wisdom:
          MODx Co-Founder - Create and do more with less.
        • I do have a related question for you core gurus. Is there a way to tie a plugin to a TV so that it will only run if the TV is present in the template?

          One thing, it would be nice to not have it run at all if you don’t want it, so you just don’t put the TV in the template if you don’t want it.

          The other thing, that would make it much easier to allow the user to modify the colors and styles used to mark the search term on a document-by-document basis. For example, if I code it to have a search term with red text, and you have a template that makes all links red, it would be a Bad Thing. On the other hand, leaving it not styled and the user has to style it in his CSS is a bit awkward.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 32963
            • 1,732 Posts
            Hi Susan,

            It’s not with 0.9.0 to bind a Plugin to a TV but you can create a plugin that will look inside the template/document for a special TV. If found it can be made to execute special code.
              xWisdom
              www.xwisdomhtml.com
              The fear of the Lord is the beginning of wisdom:
              MODx Co-Founder - Create and do more with less.
            • Ok. Well, anyway, I added configuration to the plugin:

              &term1=Term1;text;color:red &term2=Term2;text;color:blue &term3=Term3;text;color:green &term4=Term4;text;color:goldenrod


              You can edit this to make it underline or background or whatever styling you want, change the colors, and you could add more if you wanted to, but I loop it in the new plugin code:

              if(isset($_GET['searched'])) {
              
                $searched = $_GET['searched'];
                $output = $modx->documentOutput; // get the parsed document
              
                $body= explode("<body>", $output); // break out the head
              
                $searchArray = explode(' ', $searched); // break apart the search terms
              
                $i = 0; // for individual class names
              
                foreach($searchArray as $word) {
                  $i++;
                  switch($i) {
                    case 1:
                      $style=$term1;
                      break;
                    case 2:
                      $style=$term2;
                      break;
                    case 3:
                      $style=$term3;
                      break;
                    case 4:
                      $style=$term4;
                      break;
                    default:
                      $i=1;
                      break;
                  }
                  $pattern = '(>[^<]*)('. quotemeta($word) .')';
                  $replacement = '\\1<span style="'.$style.'">\\2</span>';
                  $body[1] = eregi_replace($pattern, $replacement, $body[1]);
                }
              
                $output = implode("<body>", $body);
              
                $modx->documentOutput = $output;
              
              }
              
              

                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
              • Is there any way to include a ; in the configuration text:

                &term1=Term1;text;color:red;border:1px solid red &term2=Term2...
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 32963
                  • 1,732 Posts
                  Hmmm,

                  The properties tab does not escape ; at this point in time
                    xWisdom
                    www.xwisdomhtml.com
                    The fear of the Lord is the beginning of wisdom:
                    MODx Co-Founder - Create and do more with less.
                  • Might be better to have text put in quotes and take the whole string in quotes verbatim?
                      Studying MODX in the desert - http://sottwell.com
                      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                      Join the Slack Community - http://modx.org
                      • 32963
                      • 1,732 Posts
                      Quote from: sottwell at Oct 31, 2005, 07:57 AM

                      Might be better to have text put in quotes and take the whole string in quotes verbatim?

                      We will have to see which is faster.
                        xWisdom
                        www.xwisdomhtml.com
                        The fear of the Lord is the beginning of wisdom:
                        MODx Co-Founder - Create and do more with less.