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

    I try to change the template of an document but somehow i can’t. I retrieve an modDocument object and set the properties accordingly...

            $document   = $this->modx->getObject('modDocument', $id);
          
            $document->set('content', $newContent);
            $document->set('template', 0); // also tried null and 1
            if(!$document->save()) {
                $this->modx->log(modX::LOG_LEVEL_ERROR, 'An error occurred while saving document.');
            }


    The content is changed they way i want to but the the template remains the same. Any ideas?
      • 3749
      • 24,544 Posts
      What version of MODx? Can you change the template in the Manager? Are those legitimate template IDs?

      BTW, you should use this to set the content:

      $resource-setContent($newContent);


        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
        • 22757
        • 41 Posts
        I’ll remember the thing with the content.

        And yes i can change template in manager. I’m on version 2.0.4. Well 1 is a legitimate template id but i wan’t to assign no template to the resource and tried with 0 and null. If i assign no template in the manager 0 is the value passed.
          • 3749
          • 24,544 Posts
          I believe that was a bug with template saving, so you might try upgrading to 2.0.8.
            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