We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45078
    • 34 Posts
    Hi, is it possible in ModX Revo or is there an addon that will let me edit the description field (or any other tv) at once (I have several items that require the same description).

    Thanks.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      As far as I know, the closest would be to export the records for those resources as a .csv file, edit the description fields using a text editor, then us ImportX to import them back again.

      It would probably be easier to use phpMyAdmin, select the relevant resources, and edit their description fields - copy/paste would speed it up.

      There is an add-on called "Group Edit" that might do the job; I'm not real sure how it works, though.

      [ed. note: sottwell last edited this post 13 years, 1 month ago.]
        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
        • 44985
        • 27 Posts
        Hi,

        I know you can batch edit resource properties (eg. published/notpublished, hideinmenu/showinmenu) using Batcher...but I have never seen anything that batch edits resource content. That would be really, really handy though!

        Otherwise, you may have to manually manipulate your database if you know your way around phpmyadmin or something like that.

        Sar
          ☆ Flag it! - Don't forget to "star" a reply if it's answered your question smiley
          • 3749
          • 24,544 Posts
          You could do it with this utility snippet, but I'm not sure it would be easier than using QuickEdit to do them in the Manager:

          <?php
          $field = 'description';  /* field you want to change */
          
          $ids = '12,24,35,97';  /* IDs of the resources you want to edit */
          
          $text = 'New Text for the field';
          
          $docIds = explode(',', $ids);
          
          $output = '';
          
          foreach ($docIds as $docId) {
              $doc = $modx->getObject('modResource', (integer) $docId);
              if ($doc) {
                  $doc->set($field, $text);
                  $doc->save();
                  $output .= '<br />Changed document ' . $doc->get('pagetitle');
              } else {
                  $output .= '<br />Could not find document ' . $docId;
              }
          }
          
          return $output;
          


          Note that this is no good for Template Variables (description is not a Template Variable, it's a Resource field). It will only work on text type Resource fields, but it could be modified slightly to do TVs. It won't work for the template or parent fields, unless you use the ID of the template or parent in the $text variable.
            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
            • 45078
            • 34 Posts
            Thanks for the replies. I checked out Group Edit, it only allowed me to delete multiple resources, which I already user Batcher for. It would be a nice feature to have, but it seems the quickest option will be to export the resources, get the client to amend the descriptions en masse and re-import with ImportX.
              • 45078
              • 34 Posts
              Quote from: BobRay at Sep 12, 2013, 02:11 AM
              You could do it with this utility snippet, but I'm not sure it would be easier than using QuickEdit to do them in the Manager:

              <!--?php
              $field = 'description';  /* field you want to change */
              
              $ids = '12,24,35,97';  /* IDs of the resources you want to edit */
              
              $text = 'New Text for the field';
              
              $docIds = explode(',', $ids);
              
              $output = '';
              
              foreach ($docIds as $docId) {
                  $doc = $modx--->getObject('modResource', (integer) $docId);
                  if ($doc) {
                      $doc->set($field, $text);
                      $doc->save();
                      $output .= '
              Changed document ' . $doc->get('pagetitle');
                  } else {
                      $output .= '
              Could not find document ' . $docId;
                  }
              }
              
              return $output;
              


              Note that this is no good for Template Variables (description is not a Template Variable, it's a Resource field). It will only work on text type Resource fields, but it could be modified slightly to do TVs. It won't work for the template or parent fields, unless you use the ID of the template or parent in the $text variable.

              This is neat, unfortunately there is ~250 resources :|
                • 3749
                • 24,544 Posts
                Are they all under a single parent folder or a small group of them?
                  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
                  • 45078
                  • 34 Posts
                  Quote from: BobRay at Sep 12, 2013, 09:41 PM
                  Are they all under a single parent folder or a small group of them?

                  Single parent. They're product catalogue pages with no sub-categories.
                    • 3749
                    • 24,544 Posts
                    Ah. Simpler yet. wink

                    $field = 'description';  /* field you want to change */
                     
                    $text = 'New Text for the field';
                    
                    $parentId = 12; /* ID of the parent resource */
                     
                    $output = '';
                    
                    $docs = $modx->getCollection('modResource', array('parent' => $parentId));
                    
                    $output .= '<h3>Correcting ' . count($docs) . ' Resources</h3>';
                    
                    foreach ($docs as $doc) {
                        $doc->set($field, $text);
                        $doc->save();
                        $output .= '<p>Updated document ' . $doc->get('pagetitle') . '</p>';
                    }
                     
                    return $output;



                    This assumes that they're all directly under that parent folder.
                      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