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

    Does anyone know how you escape an extra '=' character when using the replace modifier?

    I have this:
    [[+url:replace=`watch?v==embed/`]]


    Which works great, but I actually want to replace 'watch?=' but if I write the snippet like this:
    [[+url:replace=`watch?v===embed/`]]


    It obviously doesn't work due to the three '===' characters together. Is there a way to escape the additional '='?

    Thanks,

    This question has been answered by BobRay. See the first response.

      ■ email: [email protected] | ■ website: https://alienbuild.uk

      The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
    • discuss.answer
      • 3749
      • 24,544 Posts
      Give this a try. I'm not sure it will work:


      [[+url:replace=`'watch?v='==embed/`]]


      If not, I don't think an output modifier will do it. You'd need a custom snippet (call it MyReplace). Something like this:

      Tag:

      [[!MyReplace? &search=`watch?v=` &replace=`embed/` &subject=`[[+url]]` ]];


      Snippet:

      /* MyReplace snippet */
      
      $search = $modx->getOption('search', $scriptProperties, false);
      $replace = $modx->getOption('replace', $scriptProperties, false);
      $subject = $modx->getOption('subject', $scriptProperties, false);
      
      if ($search && $replace && $subject) {
         return(str_replace($search, $replace, $subject));
      } else {
          $modx->log(modX::LOG_LEVEL_ERROR, '[MyReplace] Missing property');
      }
      
      return '';
      



      [ed. note: BobRay last edited this post 7 years, 1 month ago.]
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 17301
        • 932 Posts
        Thank you again, Bob.

        First method unfortunately didn't work but the second one worked like a charm.

        (Commas omitted)
        [[!MyReplace? &search=`watch?v=` &replace=`embed/` &subject=`[[+url]]`]]
          ■ email: [email protected] | ■ website: https://alienbuild.uk

          The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
          • 3749
          • 24,544 Posts
          I'm glad that worked for you. Thanks for reporting back. smiley
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting