We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42596
    • 45 Posts
    So basically I need to replace the URL's of my images OnBeforeDocSave in the main content and one of the TV's and I use the following code in a plugin to do so:

    $template = $resource->get('template');
    
    if($template == 48){
    
      $newsletterContent = $resource->get('content');
      $newUrlc = str_replace('src="assets/', 'src="http://www.mywebsite.com/assets/', $newsletterContent);
      $newsletterContent = $resource->set('content', $newUrlc);
    
      $newsletterSideBar = $resource->getTVValue('side_content');
      $newUrls = str_replace('src="assets/', 'src="http://www.mywebsite.com/assets/', $newsletterSideBar);
      $newsletterSideBar = $resource->setTVValue('side_content', $newUrls); 
    
    }
    


    This however causes problems when triggered OnBeforeDocFormSave (the content bit works fine (the first 3 lines in the if statement) but when I add the code to replace the TV it gives me a weird error when I try to save...the error just comes out as a URL...not very helpful.)

    I have another MODx install elsewhere which I use to develop and test stuff so I thought I'd try the same thing on that platform and got the same issue...so, while still in my dev environment I created two plugins. One for the content and one for the TV but the content plugin to get triggered OnBeforeDocFormSave (as I know it works already) and then the side content plugin to be triggered OnDocFormSave...and it worked! Sweet! Problem solved...

    So I move everything over to my main website and replicate everything exactly (apart from the if($template == 48) obviously changed). The content plugin works (as it always did) but the side_content plugin does not...

    What is going on here? Any ideas? The only difference in the 2 MODx installs is that my dev install is 2.2.6 and the main website is 2.2.4 (both revolution)

    Any help would be greatly appreciated!

    Thanks...

    (If anything is unclear here just say and ill try write it a bit better haha)
      • 3749
      • 24,544 Posts
      Are any of the TVs set to the TV's default value or empty?
        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
        • 42596
        • 45 Posts
        The TV is empty and then is filled when you create a new document using the correct template...
          • 42596
          • 45 Posts
          So i got it sorted...for anyone that wants to know...

          I found this: http://rtfm.modx.com/display/revolution20/Input+and+Output+Filters+(Output+Modifiers)

          and then just called the variable in the template like this: [[*side-content:replace=`src="assets==src="http://www.mywebsite.com/assets`]]